我正在尝试实现同样的事情这个问题,但长桌环境。表格本身居中。
使用标题包装和
\captionsetup[longtable]{justification=raggedright,singlelinecheck=off}
使标题左对齐,但标题超出了表格的左边缘。
我不能只是添加margin=
或做其他事情,因为我的表格的宽度不一样。
有没有办法纠正这个问题,或者也许有替代方案长桌?
示例文档:
\documentclass[a5paper,12pt,titlepage]{article}
\usepackage[a5paper]{geometry}
\usepackage{longtable}
\usepackage{caption}
\captionsetup[longtable]{skip=0pt,justification=raggedright,singlelinecheck=off}
\usepackage{lipsum}
\begin{document}
\lipsum[3-4]
\begin{longtable}{l|p{2.5cm}|p{2.5cm}}
%----------------------------------------
\caption{This label isn't where I want it}\label{tab:test}\\ \hline
Name & Description & Example\\
\endfirsthead
%----------------------------------------
\caption*{Table \ref{tab:test} (continued)}\\\hline
\endhead
%----------------------------------------
\hline
Something A & here's supposed to be some text & some text here \\ \hline
Something B & description of B & something more about B\\ \hline
Something C & describe C here & some example involving C \\ \hline
Something D & dfjashdfkjha sdflhasdkf hfsadf asdf & dsjkdlaskd ksjdla jdlkasj \\ \hline
\end{longtable}
\end{document}
标题对齐如下:
我想要的效果如下:
答案1
您可以通过设置\LTcapwidth
表格宽度来确定标题的起始宽度。由于其宽度是不知道的(预先),所以只能通过“反复试验”的方法...
\documentclass[a5paper,12pt,titlepage]{article}
\usepackage[a5paper]{geometry}
\usepackage{longtable}
\usepackage{caption}
\captionsetup[longtable]{skip=0pt,justification=raggedright,singlelinecheck=off}
\usepackage{lipsum}
\begin{document}
\lipsum[3-4]
{\setlength\LTcapwidth{0.85\linewidth}
\begin{longtable}{l|p{2.5cm}|p{2.5cm}}
%----------------------------------------
\caption{This label isn't where I want it}\label{tab:test}\\ \hline
Name & Description & Example\\
\endfirsthead
%----------------------------------------
\caption*{Table \ref{tab:test} (continued)}\\\hline
\endhead
%----------------------------------------
\hline
Something A & here's supposed to be some text & some text here \\ \hline
Something B & description of B & something more about B\\ \hline
Something C & describe C here & some example involving C \\ \hline
Something D & dfjashdfkjha sdflhasdkf hfsadf asdf & dsjkdlaskd ksjdla jdlkasj \\ \hline
\end{longtable}
}
\end{document}
读:
如果您喜欢使用ltablex
宽度,则标题框的宽度与表格的宽度相同。因此,它是提前知道的,并且表格的设置更简单。例如:
\documentclass[a5paper,12pt,titlepage]{article}
\usepackage[a5paper]{geometry}
\usepackage{ltablex}
\usepackage{caption}
\captionsetup[longtable]{skip=0pt,justification=raggedright,singlelinecheck=off}
\usepackage{lipsum}
\begin{document}
\lipsum[3-4]
{\setlength\LTcapwidth{0.9\linewidth}
\begin{tabularx}{0.9\linewidth}{l|X|X}
%----------------------------------------
\caption{This label is where I want it}\label{tab:test}\\
\hline
Name & Description & Example\\
\endfirsthead
%----------------------------------------
\caption*{Table \ref{tab:test} (continued)}\\\hline
\endhead
%----------------------------------------
\hline
Something A & here's supposed to be some text & some text here \\ \hline
Something B & description of B & something more about B\\ \hline
Something C & describe C here & some example involving C \\ \hline
Something D & dfjashdfkjha sdflhasdkf hfsadf asdf & dsjkdlaskd ksjdla jdlkasj \\ \hline
\end{tabularx}
}
\end{document}
这使: