我想将文档中的长表调整为文本宽度。最好的方法是什么?
我当前使用的代码是:
\documentclass{article}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{longtable}
\usepackage{luatextra}
\defaultfontfeatures{Ligatures=TeX}
\textwidth = 400pt
\begin{document}
\lipsum
\begin{longtable}[h]{|p{3cm}|p{2cm}|p{4cm}|p{6cm}|}
\rowcolor{white}\caption{Universal PCR - master reaction mix\label{table:Table8}}
\hline
\rowcolor{blue}\textcolor[rgb]{1,1,1}{Universal PCR} & \textcolor[rgb]{1,1,1}{PCR Mix} & \textcolor[rgb]{1,1,1}{AR 1} &\textcolor[rgb]{1,1,1}{Taq DNA polymerase}\\
\hline
\endhead
11 & 110 µl & 63.25 µl & 2.75 µl\\
\hline
25 & 250 µl & 143.75 µl & 6.25 µl\\
\hline
\end{longtable}
\end{document}
答案1
您可以计算宽度,考虑规则和列填充,然后选择分配给每列的剩余宽度的比例:
\documentclass{article}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{longtable}
\usepackage{luatextra}
\defaultfontfeatures{Ligatures=TeX}
\textwidth = 400pt
\newlength\mylength
\begin{document}
\lipsum
\setlength\mylength{\dimexpr\textwidth-5\arrayrulewidth-8\tabcolsep}
\begin{longtable}{|p{.3\mylength}|p{.2\mylength}|p{.25\mylength}|p{.25\mylength}|}
\rowcolor{white}\caption{Universal PCR - master reaction mix\label{table:Table8}}\\
\hline
\rowcolor{blue}\textcolor[rgb]{1,1,1}{Universal PCR} & \textcolor[rgb]{1,1,1}{PCR Mix} & \textcolor[rgb]{1,1,1}{AR 1} &\textcolor[rgb]{1,1,1}{Taq DNA polymerase}\\
\hline
\endhead
11 & 110 µl & 63.25 µl & 2.75 µl\\
\hline
25 & 250 µl & 143.75 µl & 6.25 µl\\
\hline
\end{longtable}
\end{document}