\documentclass{article}
\usepackage{tabularx}
\usepackage{tikz}
\begin{document}
\begin{tabularx}{\linewidth}{c|X}
\begin{tikzpicture}[
scale=.6,
every node/.style={scale=.6}
]
\path[draw] (0,0) rectangle
+(3,2) node [pos=.5] {rectangle}
+(3,1.5) node[anchor=east] (a) {A}
+(3,0.5) node[anchor=east] (b) {B};
\end{tikzpicture}
&
\begin{tabular}{l}
This line is not aligned vertically top\\
This is another line below the first one
\end{tabular}
\end{tabularx}
\end{document}
在这个例子中,一个小的 tikz 图片改变了文本的基线,以便下一个单元格从单元格的底部开始。我希望基线保持在原来的位置,并让 tikz 图片自行插入而不改变它。这样,我后续的输入就会留在单元格的顶部。
我怎样才能使我的第二个单元格垂直对齐顶部?
答案1
如果您只是添加[t]
到表格中,最初它会向下移动,因为顶行将与图片底部对齐。然后您想将图片的基线放在底部以外的某个地方,例如节点 a 的基线。:
\documentclass{article}
\usepackage{tabularx}
\usepackage{tikz}
\begin{document}
\begin{tabularx}{\linewidth}{c|X}
\begin{tikzpicture}[
baseline={(a.base)},
scale=.6,
every node/.style={scale=.6}
]
\path[draw] (0,0) rectangle
+(3,2) node [pos=.5] {rectangle}
+(3,1.5) node[anchor=east] (a) {A}
+(3,0.5) node[anchor=east] (b) {B};
\end{tikzpicture}
&
\begin{tabular}[t]{l}
This line is not aligned vertically top\\
This is another line below the first one
\end{tabular}
\end{tabularx}
\end{document}