Skip to content

Instantly share code, notes, and snippets.

@yarakos95
Last active December 28, 2025 16:04
Show Gist options
  • Select an option

  • Save yarakos95/db3c82385811eccef5f0e53b0d1b8917 to your computer and use it in GitHub Desktop.

Select an option

Save yarakos95/db3c82385811eccef5f0e53b0d1b8917 to your computer and use it in GitHub Desktop.
TikZを利用してluatexjaマニュアルの図14のようなボックスを再現する[LaTeX]
%% The MIT License Copyright (c) 2025 Yarakashi Kikohshi
%% TikZを利用することを前提とする
%% \outbox*{<ボックスの数>}{<ボックスに囲われる文字>}[<tikzmarkのための座標名>]
%% \outbox{3}{あいうえお} とすることで、`あいう' までボックスで囲われる。`えお' はこれに続く。
%% 折り返しには対応していない
%% \outbox* とすることで、先頭のボックスに ■ の背景を与える
%% 任意の場所に ■ 背景を与えるようにはしていない
%% \outbox{}{}[A] とすることで、tikzmark を介して外部に座標名を提供する
%% この場合の座標名は outboxA となる
%% 加えて左端辺の上下中央にドットと短い水平線を与える
\definecolor{b_cyan}{rgb}{0.70, .92, 98}
\NewDocumentCommand{\outbox}{ s m m o }{%
\noindent
\begin{tikzpicture}[baseline=(text.base), remember picture]
\begin{scope}[overlay, yshift=-0.12\zw, color=b_cyan]
\node[draw=b_cyan, line width=.4pt,
minimum width=1\zw, minimum height=1\zw,
inner sep=0pt] (c1)
at (0,0) {};
\IfBooleanT{#1}{\node[minimum size=0.7\zw, fill] {};}
\draw[line width=.4pt] ($(c1.south west)+(0.5\zw,0)$) -- ++(0,0.2\zw);
\foreach \i in {2,...,#2} {
\node[draw=b_cyan, line width=.4pt,
minimum width=1\zw, minimum height=1\zw,
inner sep=0pt] (c\i)
at ({(\i-1)*1\zw},0) {};
\draw[line width=.4pt] ($(c\i.south west)+(0.5\zw,0)$) -- ++(0,0.2\zw);
}
\IfNoValueF{#4}
{
\fill (c1.west) circle[radius=.1\zw];
\draw[line width=.4pt]
($(c1.west)+(-.5\zw,0)$) -- (c1.west);
\coordinate[remember picture] (outbox#4) at (c1.west);
}
\end{scope}
\node[anchor=north west, inner sep=0pt] (text)
at (c1.north west) {#3};
\end{tikzpicture}
}
@yarakos95
Copy link
Author

特に意味のない例:

\documentclass{jlreq}
%%%% 上の定義を入れる
\begin{document}

\outbox*{5}{ある日の暮方の事である。}[A]%
一人の下人が、羅生門の下で雨やみを待っていた。

\outbox*{5}{広い門の下には、この男のほかに誰もいない。}[B]

\begin{tikzpicture}[remember picture, overlay]
  \draw[<->, line width=.4pt]
    ($(outboxA)+(-0.5\zw,0)$)
      --
    ($(outboxB)+(-0.5\zw,0)$)
    node[midway, left] {\scriptsize 行送り};
\end{tikzpicture}


\end{document}
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment