3

I'm trying to create a subdirectory for all of my tables and use it in a similar way to \graphicspath. I have a lot of tables and don't want to see them in my main text.

9
  • 1
    We are going to need some more detail here: tables are (normally) just part of the source. – Joseph Wright Dec 22 '15 at 18:35
  • 3
    You probably can use \input command to externalize your table – Romain Picot Dec 22 '15 at 18:36
  • one \input for each table? – Nicolás Sacco Dec 22 '15 at 18:40
  • 1
    Then you can define a command for each table - all in the "same_place.tex" file, \input it, and just call the appropriate command when needed. – alwaysask Dec 22 '15 at 18:50
  • 2
    @NicolásSacco: Sorry, I have to remark that the kind of your questions is often very broad or unclear. Basically no MWE, only confusing comments or additional requests, but you've neither upvoted the answers to your questions nor accepted (some) of the answers (No, I am not one of the users who answered one of your questions.) -- In my point of view this disrespecting the efforts of the community here :-( – user31729 Dec 22 '15 at 19:13
2

To have tables in separate file(s) in a subdirectory, you can do something like this:

  • make a subdirectory (say "tables")

  • create a tex file in that subdirectory containing new commands with the table definitions, say the file "chapter1tables.tex" containing:

    \newcommand*\TableOneOne{%
        \begin{tabular}{|c|c|}
          \hline 1 & a \\ 
          \hline 2 & b \\ 
          \hline 
        \end{tabular}
    }
    
  • input the "chapter1tables.tex" file(s) in your main tex file

  • call your defined commands for the tables when needed:

    \documentclass{article}
    \input{tables/chapter1tables}
    
     \begin{document}
       Here comes the table: 
    
       \TableOneOne
     \end{document}
    
5

Here is something similar to \includegraphics and \graphicspath. If \tablepath isn't defined the command tries to include the filename given as argument from the current directory.

If \tablepath is defined, it will look if the file exists there, otherwise it will try to use the local directory (again)

\documentclass{article}

\newcommand{\tablepath}{mytables}

\makeatletter
\newcommand{\includetable}[1]{%
  \@ifundefined{tablepath}{%
    \InputIfFileExists{#1}{}{}%
  }{%
    \InputIfFileExists{\tablepath/#1}{}{\InputIfFileExists{#1}{}{}}%
  }
}
\makeatother    



\begin{document}

\includetable{tablea}

\includetable{tableb}



\end{document}

Here are the definitions of tablea and tableb:

tablea.tex

\begin{tabular}{ll}
\hline
A & B \tabularnewline
\hline
\end{tabular}

tableb.tex -- I've stored this in my mytables directory.

\begin{tabular}{ll}
\hline
C & D \tabularnewline
\hline
\end{tabular}
1
  • Please note: This is a quick hack, nothing fully reliable, due lack of time – user31729 Dec 22 '15 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.