![命令将文本放置在特定位置,无论长度](https://linux22.com/image/425565/%E5%91%BD%E4%BB%A4%E5%B0%86%E6%96%87%E6%9C%AC%E6%94%BE%E7%BD%AE%E5%9C%A8%E7%89%B9%E5%AE%9A%E4%BD%8D%E7%BD%AE%EF%BC%8C%E6%97%A0%E8%AE%BA%E9%95%BF%E5%BA%A6.png)
我有以下代码:
\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%landmark
\draw [lightgray] (0, 0) -- (0,-1.5);
\node at (0.45,-0.2) {Hello};
\node at (1.4,-1) {Hello my friend};
\end{tikzpicture}
\end{document}
它给出以下输出:
我希望文本从灰色标记开始,但正如您所见,当文本长度发生变化时,x 位置也需要更改。有没有办法“自动化”这个 x 编辑过程?因为对于大型文档来说,这会变得很烦人。(也许答案在网络上的某个地方,我只是不知道如何正确地用谷歌搜索我的问题)
答案1
使用\node[anchor=west, inner xsep=0pt]
。
分步示例:
\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%landmark
\draw [lightgray] (0, .5) -- (0,-4);
% original, equivalent to "anchor=center, inner xsep=.3333em"
\node at (0.45, 0) {Hello};
\node at (1.4, -.5) {Hello my friend};
% with "anchor=west" added and the x-pos of node being "0"
\node[anchor=west] at (0, -1.5) {Hello};
\node[anchor=west] at (0, -2) {Hello my friend};
% with "inner xsep=0pt" added and syntax "\path node {...} node {...};" applied
\path[anchor=west, inner xsep=0pt]
node at (0, -3) {Hello}
node at (0, -3.5) {Hello my friend};
\end{tikzpicture}
\end{document}