1

I'm exporting a LaTeX table from Stata and adding it into a document using the input command. However, I don't want the document to display the last column in this table. The table file is going to be regenerated (overwritten) on a regular basis and so I don't want to edit it every single time. Is there a way to not show the column without editing the table file itself?

table.tex:

\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Table}
\begin{tabular}{l*{3}{cc}}
...
\end{tabular}
\end{table}

main.tex:

\begin{document}
...
\input{table.tex}
...
\end{document}
Parth
  • 175
  • 1
    luaprogtable package might be what you are looking for. Its fairly new and I have never used it, so I cannot give you specific solution. Docs say about modifying tables, maybe it will be helpfull. – Tomáš Kruliš Sep 21 '20 at 14:39
  • @JohnKormylo I was thinking along the same lines but that requires that you can set the column type that is exported, this may not be possible. – Marijn Sep 21 '20 at 15:01
  • Maybe you can write a preprocessing script in another language (Perl, Python, even sed or similar) and call that (with \write18) just before you call \input? – Marijn Sep 21 '20 at 15:03
  • Is it that you can't modify table.tex, or you just don't want to change every line of the data? I would keep the \begin{table} commands outside the file and leave only the contents. – John Kormylo Sep 21 '20 at 15:16
  • See http://tex.stackexchange.com/questions/16604/easiest-way-to-delete-a-column/16607#16607 – John Kormylo Sep 21 '20 at 15:26
  • @JohnKormylo The file gets overwritten whenever the Stata code is run, and this happens on a regular basis. Then I only have to recompile the main tex file to update the data. Stata exports the file with the \begin{table} commands so it would be annoying to delete that each time. – Parth Sep 21 '20 at 16:57
  • @Marijn thanks, but don't think I'd know how to do that. – Parth Sep 21 '20 at 16:59
  • @vader9280 which operating system do you use (Windows/Mac/Linux)? Do you have any programming language installed? I'm not sure but I think MikTeX (Windows) comes with a version of Perl because some helper programs use it. – Marijn Sep 21 '20 at 21:31

1 Answers1

6

You can temporarily modify tabular to ignore the given argument and replace it with something else.

File temp.tex:

\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Table}
\fboxsep=0pt
\fbox{\begin{tabular}{cc}
a & b \\
c & d
\end{tabular}}
\end{table}

Test document:

\documentclass{article}
\usepackage{array}

\newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{\hspace{-\tabcolsep}}}

\begin{document} \input{temp.tex}

{% begin group \let\normaltabular=\tabular \let\endnormaltabular=\endtabular \renewenvironment{tabular}[1]{\normaltabular{cH}}{\endnormaltabular}% \input{temp.tex} }% end group

\end{document}

demo

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • Works great, thanks a lot! Had to use \begin{tabular}{ccH@{\hspace*{-\tabcolsep}}} to delete the last column though, explained here: https://tex.stackexchange.com/questions/16604/easiest-way-to-delete-a-column – Parth Sep 22 '20 at 06:54
  • Oops, didn't pay attention while copying. – John Kormylo Sep 22 '20 at 13:25