\documentclass[12pt,twoside]{report}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{matrix,shadings,arrows,decorations.markings,decorations.pathmorphing}
\tikzset{
table/.style={
matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={
rectangle,
draw=black,
align=center,
},
%baseline={([yshift=-0.5ex]current bounding box.center)},
minimum height=1.0em,
text depth=0.2em,
text height=0.8em,
text centered,
nodes in empty cells,
%%
row 1/.style={
nodes={
fill=black,
text=white,
%font=\bfseries
}
},
rows/.style={nodes={fill=gray!10}},
columns/.style={nodes={text width = 10em}},
%myrowstyle/.style={
%row #1/.style={nodes={fill=gray!10}}
%},
}
}
\begin{document}
\begin{table}
\centering
\begin{tikzpicture}
\matrix[table, text width = 15em, text height = 2em, text depth = 2em, rows={1,...,10}{fill=gray!10}, row 1/.style={nodes={fill=gray!10,
text=black}}, column 2/.append style={nodes={text width=18em}},
ampersand replacement=\&] (TabA1)
{
A1 \& A2 \\
B1 \& Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. \\
};
\end{tikzpicture}
\caption{Glossary}
\label{tabA1}
\end{table}
\end{document}
两个问题:
- 我正在使用
tikz
它创建一个表格。前几行是 A(列 A1 和 A2),然后我在页面末尾。我是否需要创建另一个表格来继续 B,或者是否可以告诉tikz
它自动拆分表格? - 我不太确定如何处理文本深度和文本高度。假设 A1 只有一个单词,但 A2 是一段大文本,那么我可能必须手动调整文本高度才能使文本适合。然后我使用文本深度使其看起来不错。但是这样确实感觉很尴尬,特别是我希望 A1 位于行的中间,而不是与 A2 的第一行文本在同一行。TikZ 是否可能自动为我完成所有这些操作,还是我需要手动完成所有这些操作?
答案1
这是扩展评论...
- 不清楚为什么你喜欢使用包
matrix
中的库tikz
来设计应该分布在两页或更多页上的表 - 浮动环境
table
只能在一页上,如果内容较大,则会溢出页面 tikzpicture
图像只能在一页上。如果图像太大,则会溢出页面- 从描述中可以猜出,这实际上就是你在寻找的
longtable
。看看下面的例子是否接近你想要得到的。
\documentclass[12pt,twoside]{report}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}% option showframe is only for test purposes
\usepackage{longtable}
\usepackage[table]{xcolor}
\usepackage{lipsum}
\begin{document}
{
\setlength\tabcolsep{8pt}
\rowcolors{2}{gray!10}{gray!10}
\begin{longtable}{|p{\dimexpr0.5\linewidth-2\tabcolsep-1.5\arrayrulewidth}
|p{\dimexpr0.5\linewidth-2\tabcolsep-1.5\arrayrulewidth}|
}
\caption{Glossary}
\label{tabA1} \\
\hline
\endfirsthead
\rowcolor{white}
\caption{Glossary (cont.)} \\
\hline
\endhead
\rowcolor{white}
\multicolumn{2}{r}{\textit{continue on the next page}}
\endfoot
\hline
\endlastfoot
\lipsum[1] & \lipsum[2] \\
\hline
\lipsum[3] & \lipsum[4] \\
\hline
\lipsum[5] & \lipsum[6] \\
\end{longtable}
}
\end{document}
当然,你可以坚持tikzpicture
,但是你应该为每一页单独绘制......