下面的代码块创建了一个小框来插入单词:
\RequirePackage{tikz}
\newcommand{\cvtaga}[1]{%
\tikz[baseline]\node[anchor=base,draw=body!50,rounded corners,inner xsep=1ex,inner ysep=0.80ex,text height=1.5ex,text depth=.25ex,fill=red!10]{#1};
}
在另一个 tex 文件中,这将被多次使用,例如:
\cvtaga{Word 1}
\cvtaga{Word 2}
\cvtaga{Word 3}
\cvtaga{Word 4}
\cvtaga{Word 5}
\cvtaga{Word 6}
\cvtaga{Word 7}
\cvtaga{Word 8}
\cvtaga{Word 9}
ETC...
这会产生一堆带有单词的小方框,它们在水平方向上相隔约 1 毫米,但在垂直方向上相隔约一条线的宽度。
我尝试在节点中添加“外部分隔”设置,以更大的垂直空间分隔单词 1 到单词 9,但任何设置都没有任何效果。
如何控制单词框之间的间距?
提前非常感谢您。
答案1
欢迎来到 TeX.SE!
为了更好地理解您的问题,您应该提供一份简短但完整的文档,其中显示了您的问题。据我了解,您的问题,您希望有一个节点“链”,节点之间的垂直距离相等,如果是这种情况,请尝试考虑chains
和包positioning
库tikz
,如下所示:
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains,
positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 1mm, % or any desired vertical distance between nodes
start chain = A going below,
N/.style = {draw=red!50, rounded corners, fill=red!10,
inner xsep=1ex, inner ysep=0.80ex,
text height=1.5ex, text depth=.25ex} % be aware, that with this settings width of nodes is accommodated to nodes contents widths
]
\begin{scope}[nodes={N, on chain=A}]
\node {Word 1};
\node {Word 2};
\node {Word 3};
\node {Word 4};
\node {Word 5};
\node {Word 6};
\node {Word 7};
\end{scope}
\end{tikzpicture}
\end{document}
如果您喜欢通过箭头连接节点,则宏˙join 会有很大帮助:
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains,
positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 3mm, % or any desired vertical distance between nodes
start chain = A going below,
arr/.style = {-Stealth, semithick},
N/.style = {draw=red!50, rounded corners, fill=red!10,
inner xsep=1ex, inner ysep=0.80ex,
text height=1.5ex, text depth=.25ex},
]
\begin{scope}[nodes={N, on chain=A, join=by arr}]
\node {Word 1};
\node {Word 2};
\node {Word 3};
\node {Word 4};
\node {Word 5};
\node {Word 6};
\node {Word 7};
\end{scope}
\end{tikzpicture}
\end{document}
答案2
像这样:
使用以下代码:
\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{center}
\begin{tikzpicture}[POS/.style={anchor=base,draw=red!50,rounded corners,inner xsep=1ex,inner ysep=0.80ex,text height=1.5ex,text depth=.25ex,fill=red!10}]
\node[POS] (w1) {Word1};
\node[POS] (w2) [below= of w1] {Word2};
\node[POS] (w3) [below= of w2] {Word3};
%optional
\draw[-latex] (w1)--(w2);
\draw[-latex] (w2)--(w3);
\end{tikzpicture}
\end{center}
\end{document}