下面的第 1 行与其他行有什么不同?空间宽度减小了。(这似乎是通过样式启用的text width=something
;如果我删除它,则压缩不存在,但我会得到居中的文本。)除了强制节点宽度外,还有什么方法可以修复它吗?(例如,用于绘制节点边框)
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{}
\begin{document}
\begin{tikzpicture}
\tikzset{
bytesbox/.style={minimum width = 10cm, text width=10cm, align=left},
}
\node[bytesbox, anchor=west] at (0,1cm) {\tt 1 AB CD EF GH IJ KL};
\node[bytesbox, anchor=west] at (0,0.5cm) {\tt 2.AB.CD.EF.GH.IJ.KL};
\node[anchor=west] at (0,0) {\tt 3 AB CD EF GH IJ KL};
\node[anchor=west] at (0,-0.5) {\tt 4 AB.CD.EF.GH.IJ.KL};
\end{tikzpicture}
\end{document}
答案1
您需要node font=\ttfamily
(或font=\ttfamily
),\tt
或者将节点的文本换行\texttt
(据我所知) 是错误的。pgfmanual v3.1.5b 在第 233 页上说
你需要align=flush left
。pgfmanual v3.1.5b 在第 236 页上说
\documentclass[border=4]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\tikzset{
bytesbox/.style={minimum width = 10cm, text width=10cm, align=flush left},
}
\node[bytesbox, anchor=west,node font=\ttfamily] at (0,1cm) {1 AB CD EF GH IJ KL};
\node[bytesbox, anchor=west,node font=\ttfamily] at (0,0.5cm) {2.AB.CD.EF.GH.IJ.KL};
\node[anchor=west,node font=\ttfamily] at (0,0) {3 AB CD EF GH IJ KL};
\node[anchor=west,node font=\ttfamily] at (0,-0.5) {4 AB.CD.EF.GH.IJ.KL};
\end{tikzpicture}
\end{document}
当然,你可以将字体信息添加到bytesbox
样式中。
\tikzset{
bytesbox/.style={minimum width = 10cm, text width=10cm, align=flush left,node font=\ttfamily},
}
答案2
这是 Ti钾\spaceskip
在文本框中篡改的 Z。
你可以用 来解决这个问题text badly ragged
。请避免\tt
使用已经被弃用了 25 年的 。
\documentclass[border=4]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\tikzset{
bytesbox/.style={minimum width = 10cm, text width=10cm, align=left,text badly ragged},
}
\node[bytesbox, anchor=west] at (0,1cm) {\texttt{1 AB CD EF GH IJ KL}};
\node[bytesbox, anchor=west] at (0,0.5cm) {\texttt{2.AB.CD.EF.GH.IJ.KL}};
\node[anchor=west] at (0,0) {\texttt{3 AB CD EF GH IJ KL}};
\node[anchor=west] at (0,-0.5) {\texttt{4 AB.CD.EF.GH.IJ.KL}};
\end{tikzpicture}
\end{document}
答案3
\spaceskip=0.5em
似乎允许我修复它。(不确定为什么是0.5em
而不是1em
)
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{}
\begin{document}
\begin{tikzpicture}
\tikzset{
bytesbox/.style={minimum width = 10cm, text width=10cm, align=left},
bytesbox2/.style={minimum width = 10cm, text width=10cm, font={\ttfamily}, align=left, execute at begin node={\spaceskip 0.5em}},
}
% phantom space
\def\psp{\phantom{0}}
\node[bytesbox, anchor=west] at (0,1cm) {\tt\spaceskip=0.5em 1 AB CD EF GH IJ KL};
\node[bytesbox, anchor=west] at (0,0.5cm) {\tt 2.AB.CD.EF.GH.IJ.KL};
\node[anchor=west] at (0,0) {\tt 3 AB CD EF GH IJ KL};
\node[anchor=west] at (0,-0.5) {\tt 4 AB.CD.EF.GH.IJ.KL};
\node[bytesbox2, anchor=west] at (0,-1cm) {5 AB CD EF GH IJ KL};
\end{tikzpicture}
\end{document}