1

I have used \tikzexternalize successfully with various plots in my document, and I am looking for a way to do this for arbitrary latex code.

For example, suppose I have the document:

\documentclass{article}

\begin{document}

Some text here.

\begin{tabular}{c}
  Lots of stuff\\
  Lots of stuff
\end{tabular}

And some text after the table.

\end{document}

How can I achieve something like the following?

\documentclass{article}
\usepackage{graphicx}

\begin{document}

Some text here.

\includegraphics{that-table-from-above}

And some text after the table.

\end{document}

What I am looking for is a way to export the result of arbitrary latex code into vector graphics, along the lines of (an imaginary command)

\export@this@to{loads of code here}{exported-file.pdf}

5
  • 1
    A table is not a graphics, for good reasons. For instance, if you were to change the font size, you'd want these changes also to be applied to your table(s).
    – user121799
    Jan 9 '18 at 16:30
  • 2
    just put the tabular into a separate document and include the resulting pdf (it gets harder if the content depends on the context in the main docuemnt, eg section numbers etc so it depends on how automated you want to be and how general the text to be exported is) particularly tricky would be a \ref in the tabular to a section in the main document. Jan 9 '18 at 17:37
  • 1
    Maybe the subfiles package could be of interest. It allows externalizing and compiling parts of your document into their own pdf while keeping the same preamble as your main document. The (potential, depending on use-case) downside is that the externalized pdf is not cropped like externalized tikzpictures; it has the same page size as the original document. The standalone package might also be worth a look, though I'm not sure how well it would work here for the reasons marmot mentioned; I've only ever tried it for graphics. Jan 9 '18 at 22:21
  • @marmot Also true for images if they include text.
    – cfr
    Jan 10 '18 at 1:34
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. Jan 20 '18 at 14:24
1

And what about including table in a node?

\begin{tikzpicture}
\path node at (0,0) {\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
$s$ & 0 & \ldots & 0 & $e_n$ & $e_{n-1}$ & \ldots & $e_0$\\
\hline
\multicolumn{1}{c}{znak} & \multicolumn{7}{@{}c@{}}{\upbracefill}\\
\multicolumn{1}{c}{} & \multicolumn{7}{c}{$d$ binary digits}
\end{tabular}};
\end{tikzpicture}

using externalize, of course.

On the other hand, sometimes, it is better to create additional document containing “external graphics”.

1

In general can just put the table code into an extra .tex file of its own and then use \input{<filename>} where you want it.

If you want to generate a graphic from the code and include this one, then you can use the standalone class and package. Both in combination allows for compiling the content into an image and include it like a graphics using \includestandalone.

You need to place the table code into an own file yourself with \documentclass{standalone} and in the main document use \usepackage[mode=buildnew]{standalone} and then \includestandalone{<subfilename>}. The LaTeX compiler needs to be executed with -shell-escape option enabled so that the image can be build.

If you only want to include the code like an image, use mode=tex (default) instead. Then you don't need shell escape as well.

See the standalone manual for more details.

0

What has worked for me (and the easiest way from what I gather) is to do the following:

\begin{tikzpicture}
  \node at (0,0) {
    % Whatever latex code you want here.
  };
\end{tikzpicture}

The above uses the tikz package to turn whatever you want into a tikzpicture. You will obviously need this in the preamble:

\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize

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.