我正在尝试绘制一个位于矩形底部边框正上方中心的标签,但我不知道如何使用 tikz 将其放置在那里。有人能告诉我如何将标签放置在这个位置吗
\documentclass[a4paper,11pt]{report}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture} [remember picture,overlay]
\node (rect) [rectangle, draw, minimum width=70mm, minimum height=100mm, anchor= south west] at (0,0) {};
\node (rect.center) {Centered Above Bottom Border};
\end{tikzpicture}
\end{document}
答案1
您可以添加带有锚点的label
at 。south
rect
south
label={[anchor=south]south:Centered Above Bottom Border}
代码:
\documentclass[a4paper,11pt]{report}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture} [remember picture,overlay]
\node (rect) [rectangle, draw, minimum width=70mm, minimum height=100mm, anchor= south west,label={[anchor=south]south:Centered Above Bottom Border}] at (0,0) {};
%\node (rect.center) {Centered Above Bottom Border};
\end{tikzpicture}
\end{document}
如果希望标签作为单独的节点,请将节点放在适当的位置:
\node[anchor=south] at (rect.south) {Centered Above Bottom Border};
代码:
\documentclass[a4paper,11pt]{report}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture} [remember picture,overlay]
\node (rect) [rectangle, draw, minimum width=70mm, minimum height=100mm, anchor= south west] at (0,0) {};
\node[anchor=south] at (rect.south) {Centered Above Bottom Border};
\end{tikzpicture}
\end{document}
答案2
不要向西南方向抛锚,而要向南方向抛锚,并告诉 tikz 将你的线放在锚点上方:
\documentclass[a4paper,11pt]{report}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture} [remember picture,overlay]
\node (rect) [rectangle, draw, minimum width=70mm, minimum height=100mm, anchor= south] at (0,0) {};
\node [above] (rect.center) {Centered Above Bottom Border};
\end{tikzpicture}
\end{document}
编辑考虑到@Zarko 的评论
删除了该[remember picture,overlay]
部分,因为在本 MWE 的上下文中,它会扭曲矩形在页面上的位置
完全取消了锚点,因为如果你正确使用节点名称,你就不需要它了
\documentclass[a4paper,11pt]{report}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node (rect) [rectangle, draw, minimum width=70mm, minimum height=100mm] at (0,0) {};
\node [above] at (rect.south) {Centered Above Bottom Border};
\end{tikzpicture}
\end{document}