2

I just want to replace the first @{} as @{ \extracolsep{\fill} } show in MWE's comment. When try to use \patchcmd, it failed!

You know, I have a lot of this style table in my document. So want to some automatic code to do this patch work.

Thanks a lot in advance!

MWE:

\documentclass{article}
\usepackage{longtable,booktabs}

\setlength\LTleft{0pt}
\setlength\LTright{0pt}

\begin{document}

\begin{longtable}[]{@{}llll@{}} %\begin{longtable}[]{@{\extracolsep{\fill}}llll@{}} \caption{\label{tab:simple-table} A Table}\tabularnewline \toprule Name & Income & Job & Color \ \midrule \endfirsthead \toprule Name & Income & Job & Color \ \midrule \endhead Jane & 123456 & Research Assistant & red \ John & 50 & N/A & blue \ William & 3200 & Cleaner & blue \ \bottomrule \end{longtable}

\end{document}

user26992
  • 93
  • 3
  • it woul be better to change your source than use a tex patch. also it wouldnt matter if you changed them all having two identical settings makes no difference – David Carlisle Sep 10 '22 at 06:19
  • 1)The source .tex is produced from pandoc. 2)Both replace the @{ } as the same @{ \extracolsep{\fill} } also ok, but HOW to do this patch? – user26992 Sep 10 '22 at 08:17
  • you must presumably be specifying somewhere the tabular preamble llll ? (I don't have pandoc installed) – David Carlisle Sep 10 '22 at 08:22
  • I just use pandoc.exe to convert the .markdown to .tex. You know, the other tables may be have different tabular, such as rcclll or cccrrrrrrrrrrrlll, not fixed settings. – user26992 Sep 10 '22 at 08:40
  • https://tex.stackexchange.com/questions/595615/how-can-i-reformat-a-table-using-markdown-pandoc-pdf – David Carlisle Sep 10 '22 at 08:44
  • @David Carlisle This link is very usefull. Thanks! – user26992 Sep 10 '22 at 12:46

1 Answers1

2

I'm not sure I understand what you're trying to achieve. At any rate, I'd say that in addition to modifying the argument of the \begin{longtable} directive, you should also provide \endfoot and \endlastfoot directives and consider using an S column type for the second column, so that the numbers can be aligned on their respective (implied) decimal markers.

enter image description here

\documentclass{article}
\usepackage{longtable,booktabs,siunitx}

\setlength\LTleft{0pt}
\setlength\LTright{0pt}

\begin{document}

\begin{longtable}{@{\extracolsep{\fill}} l S[table-format=6.0,group-minimum-digits=4] ll @{}}

%% headers and footers:

\caption{A Table} \label{tab:simple-table} \ \toprule Name & {Income} & Job & Color \ \midrule \endfirsthead

\multicolumn{4}{@{}l}{\tablename\ \thetable, continued}\[0.5ex] \toprule Name & {Income} & Job & Color \ \midrule \endhead

\midrule \multicolumn{4}{r@{}}{\small (continued on following page)} \ \endfoot

\bottomrule \endlastfoot

%% body of table:

Jane & 123456 & Research Assistant & red \ John & 50 & N/A & blue \ William & 3200 & Cleaner & blue \

\end{longtable}

\end{document}

Mico
  • 506,678