%20%E3%81%A8%E3%81%A8%E3%82%82%E3%81%AB%E4%BD%BF%E7%94%A8%E3%81%95%E3%82%8C%E3%81%BE%E3%81%99%E3%80%82.png)
次のコードはpgf
マニュアルからの抜粋です。
Top align:
\tikz[baseline=(current bounding box.north)]
\draw (0,0) rectangle (1cm,1ex);
この位置(現在の境界ボックスの北)のベースラインを 3pt 上げるつもりなので、yshift
次のように試しました。
Top align:
\tikz[baseline=[yshift=3pt](current bounding box.north)]
\draw (0,0) rectangle (1cm,1ex);
しかし、コンパイルに合格できません。
私の質問について誰か助けてくれませんか?
MWE:
\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.misc}
\begin{document}
Top align:
\tikz[baseline=(current bounding box.north)]
\draw (0,0) rectangle (1cm,1ex);
\end{document}
答え1
私のコメントを変換して拡張してみましょう:
- 位置を定義する
current bounding box
\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}
Top align:
\tikz[baseline={([yshift=1ex] current bounding box.north)}]
\draw (0,0) rectangle (1cm,1ex);
\end{document}
注:shift
何らかの座標は、座標が記述される親の内側にある必要があります。([yshift=...] <coordinate>)
座標が角括弧内のオプション (tikzpicture
何らかの の決定への、またはへの\coordinate
) として指定されている場合は、上記の MWE で行われているように、中括弧で囲む必要があります。
- を使わずに位置を定義する
current bounding box
:
\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}
Aligned with a text
\tikz[baseline]
\draw (0,0) rectangle (1cm,1ex);
and displaced for some amount:
\tikz[baseline=2ex]
\draw (0,0) rectangle (1cm,1ex);