![在 tikz 中对齐项目和文本](https://linux22.com/image/390212/%E5%9C%A8%20tikz%20%E4%B8%AD%E5%AF%B9%E9%BD%90%E9%A1%B9%E7%9B%AE%E5%92%8C%E6%96%87%E6%9C%AC.png)
我刚开始使用 TikZ,在对齐项目方面遇到了一些问题。我想添加一些关于我的框的描述。我的计划是添加描述\node
并用线条连接起来\draw
。我现在的问题是,文本和项目是右对齐的。我如何将其左对齐?示例:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,angles,calc,positioning,shapes,shadows,arrows.meta,arrows}
\begin{document}
\begin{figure}[htbp]
\begin{tikzpicture}[box/.style={draw, rectangle, minimum size = 1cm,text width=8mm,align=center ,draw=black!50}]
\matrix(mtx-bez) [row sep=1cm, column sep=0cm, very thick]{
\node (mat) [box] {C\\};
&\node (besch) [box] {17\\};
&\node (beton) [box] {a\\};
&\node (knt) [box] {0\\};
\\};
\matrix(mtx-tex) [right=5mm of mtx-bez, row sep=1cm, column sep=0cm, very thick]{
\node (tex) [box] {3200\\};
\\};
\matrix(mtx-einbl) [right=5mm of mtx-tex, row sep=1cm, column sep=0cm, very thick]{
\node (einbl) [box] {X3\\};
\\};
\matrix(mtx-nr) [right=5mm of mtx-einbl, row sep=1cm, column sep=0cm, very thick]{
\node (vers) [box] {V\\};
& \node (nr) [box]{01\\};
\\};
%\node (probennr) [align=center] at (9,-2){Probennummer 01-05};
\node [below right =2cm and 0.5cm of vers.south, anchor=west, align=left] (versart) {Versuchsart:};
\node [below=7.5mm of versart,anchor=west, align=left, text width=4cm ] (versopt) {
\begin{itemize}
\item [\textbf{V}...Verbundversuch]
\item [\textbf{Z}...Zugversuch]
\item [\textbf{T}...Querzug]
\end{itemize}
};
\begin{scope}[shorten >= 2mm, shorten <=2mm]
\draw (knt.east) -- (tex.west);
\draw (tex.east) -- (einbl.west);
\draw (einbl.east) -- (vers.west);
%\draw [dotted] (nr.south) |- (probennr);
\draw [dotted] (vers) |- (versart.west);
\end{scope}
\end{tikzpicture}
\caption{Versuchskörperbezeichnung}
\label{fig:bezeichnung}
\end{figure}
\end{document}
答案1
您正在将文本插入\itemize
的[]
环境中。如果您将其删除并将锚点更改为east
(可选),
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,angles,calc,positioning,shapes,shadows,arrows.meta,arrows}
\begin{document}
\begin{figure}[htbp]
\begin{tikzpicture}[box/.style={draw, rectangle, minimum size = 1cm,text width=8mm,align=center ,draw=black!50}]
\matrix(mtx-bez) [row sep=1cm, column sep=0cm, very thick]{
\node (mat) [box] {C\\};
&\node (besch) [box] {17\\};
&\node (beton) [box] {a\\};
&\node (knt) [box] {0\\};
\\};
\matrix(mtx-tex) [right=5mm of mtx-bez, row sep=1cm, column sep=0cm, very thick]{
\node (tex) [box] {3200\\};
\\};
\matrix(mtx-einbl) [right=5mm of mtx-tex, row sep=1cm, column sep=0cm, very thick]{
\node (einbl) [box] {X3\\};
\\};
\matrix(mtx-nr) [right=5mm of mtx-einbl, row sep=1cm, column sep=0cm, very thick]{
\node (vers) [box] {V\\};
& \node (nr) [box]{01\\};
\\};
%\node (probennr) [align=center] at (9,-2){Probennummer 01-05};
\node [below right =2cm and 0.5cm of vers.south, anchor=west, align=left] (versart) {Versuchsart:};
\node [below=7.5mm of versart,anchor=center, align=left, text width=4cm ] (versopt) {
\begin{enumerate}
\item[] \textbf{V}...Verbundversuch
\item[] \textbf{Z}...Zugversuch
\item[] \textbf{T}...Querzug
\end{enumerate}
};
\begin{scope}[shorten >= 2mm, shorten <=2mm]
\draw (knt.east) -- (tex.west);
\draw (tex.east) -- (einbl.west);
\draw (einbl.east) -- (vers.west);
%\draw [dotted] (nr.south) |- (probennr);
\draw [dotted] (vers) |- (versart.west);
\end{scope}
\end{tikzpicture}
\caption{Versuchskörperbezeichnung}
\label{fig:bezeichnung}
\end{figure}
\end{document}
你会得到:
您现在可以将它定位到您想要的位置;)
。