
以下代碼來自手冊pgf
:
Top align:
\tikz[baseline=(current bounding box.north)]
\draw (0,0) rectangle (1cm,1ex);
我打算將該位置(當前邊界框.north)的基線提高 3pt,所以我嘗試如下yshift
:
Top align:
\tikz[baseline=[yshift=3pt](current bounding box.north)]
\draw (0,0) rectangle (1cm,1ex);
但編譯失敗。
有人可以幫我解答我的問題嗎?
微量元素:
\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);