我希望我的 tabularx 表格的宽度(几乎)覆盖整个页面,而不仅仅是文本宽度。这是当前的图片(带有\usepackage{showframe}
:
我希望表格的宽度与图片中右外框的宽度相同,但应用于两侧(因此两侧都会留下一点空白)。有人知道我该怎么做吗?代码如下:
\documentclass[a4paper,12pt]{article}
\usepackage[margin=1.in]{geometry}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{ltablex}
\usepackage{siunitx}[input-decimal-markers=.]
\usepackage{lipsum}
\usepackage{threeparttable}
\usepackage{showframe}
\usepackage[sort, numbers, compress]{natbib}
\usepackage{amsmath}
\usepackage{makebox}
\usepackage[font=scriptsize,labelfont=bf,labelsep=period]{caption}
\usepackage[export]{adjustbox}
\usepackage[hidelinks]{hyperref}
\begin{document}
\renewcommand{\arraystretch}{2}
\begin{tiny}
\begin{tabularx}{\linewidth}{@{}XXXXXX@{}}
\caption{a table}\\
\toprule
\multicolumn{1}{l}{1}&\multicolumn{1}{l}{2}&\multicolumn{1}{c}{3 }&\multicolumn{1}{c}{4 }&\multicolumn{1}{c}{5}&\multicolumn{1}{c}{6} \\
\midrule
\textbf{text123 test test test test test test test}&textasddsa&textasdasd&textas sada &textasd asd adas das&test 123 test 123 test 123 test 123 test 123 tesrt 123 test 123 test 123\\
\\
\bottomrule
\end{tabularx}
\end{tiny}
\end{document}
答案1
使表格更宽,因为textwidth
你有两个选择:
- 局部增加文本宽度。例如使用
adjustwidth
宏 - 将带表格的页面转换为
landscape
方向
这姆韦下面考虑这两个选项:
\documentclass[a4paper,12pt]{article}
\usepackage[margin=1 in]{geometry}
\usepackage{ragged2e}
\usepackage{booktabs, ltablex, makecell}
\keepXColumns
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\setcellgapes{3pt}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{}
\usepackage[strict]{changepage}
\usepackage{pdflscape}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}
\begin{document}
\lipsum[66]
\begin{adjustwidth}{}{-\dimexpr\marginparsep+\marginparwidth}
\footnotesize
\makegapedcells
\setlength\tabcolsep{3pt}
\begin{tabularx}{\linewidth}{@{}>{\bfseries}*{6}{L}@{}}
\caption{A wide table}\\
\toprule
\thead{1} & \thead{2} & \thead{3} & \thead{4} & \thead{5} & \thead{6} \\
\midrule
\endfirsthead
\caption*{Table~\thetable: A wide table \hfill(cont.)}\\
\toprule
\thead{1} & \thead{2} & \thead{3} & \thead{4} & \thead{5} & \thead{6} \\
\midrule
\endhead
\multicolumn{6}{r}{continue on the next page}
\endfoot
\bottomrule
\endlastfoot
% table body
text123 test test test test test test test
& textasddsa & textasdasd & textas sada & textasd asd adas das & test 123 test 123 test 123 test 123 test 123 tesrt 123 test 123 test 123 \\
\midrule
\lipsum*[66] & & & & & \\
\midrule
\lipsum*[66] & & & & & \\
\end{tabularx}
\end{adjustwidth}
\lipsum[66]
second option: table in landscape orientation
\begin{landscape}
\footnotesize
\makegapedcells
\setlength\tabcolsep{3pt}
\begin{tabularx}{\linewidth}{@{}>{\bfseries}*{6}{L}@{}}
\caption{A wide table}\\
\toprule
\thead{1} & \thead{2} & \thead{3} & \thead{4} & \thead{5} & \thead{6} \\
\endfirsthead
\caption*{Table~\thetable: A wide table \hfill(cont.)}\\
\toprule
\thead{1} & \thead{2} & \thead{3} & \thead{4} & \thead{5} & \thead{6} \\
\midrule
\endhead
\multicolumn{6}{r}{continue on the next page}
\endfoot
\bottomrule
\endlastfoot
% table body
\lipsum*[66] & & & & & \\
\midrule
\lipsum*[66] & & & & & \\
\midrule
\lipsum*[66] & & & & & \\
\end{tabularx}
\end{landscape}
\end{document}
如果某些列中的单元格包含较短的一行文本,则对于这些列使用列类型是合理的l
。