3

I'm working on a reference table for printf format strings:

\documentclass[a4paper]{article}
\usepackage{tabularx}
\usepackage{minted}
\usepackage{fontspec}
\setmonofont{ubuntu Mono}
\usepackage[a4paper, total={6in, 8in}]{geometry}
%opening
\title{\texttt{printf} Format String Reference}
\date{}
\begin{document}
\maketitle
\section*{Format specifiers}

\begin{tabularx}{\textwidth}{ |X|X|X| }
  \hline
  \texttt{\%s} & \mintinline{c}{printf("Hello \%s", "World");} & \texttt{Hello World} \\
  \hline 
  \texttt{\%d}  & \mintinline{c}{printf("\%d cats", 5);} & \texttt{5 cats} \\
  \hline
\end{tabularx}

\end{document}

I'm compiling with lualatex -shell-escape -synctex=1 -interaction=nonstopmode "printf".tex, the error I get is:

l.20 \end{tabularx}

! Package minted Error: Missing Pygments output; \inputminted was
probably given a file that does not exist--otherwise, you may need 
the outputdir package option, or may be using an incompatible build tool.

See the minted package documentation for explanation.
Type  H <return>  for immediate help.
 ...

If I move the \mintinline out of the tabularx block, it works fine. If I change the package declaration for minted to \usepackage[cache=false]{minted}, it works (slowly) but the table doesn't resize properly and the end of the code sample overlaps the next column:

1
  • Welcome to TeX.SX! tabularx has severe restrictions about verbatim material in it. On the other hand a tabularx with XXX can be easily realized with tabular.
    – egreg
    Oct 8, 2015 at 20:36

1 Answer 1

2

Here is a way using tabular as suggested by egreg.

\documentclass{article}
\usepackage{array}

\usepackage{minted}
\usepackage{fontspec}
\setmonofont{ubuntu Mono}
\usepackage[a4paper, total={6in, 8in}]{geometry}
%opening
\title{\texttt{printf} Format String Reference}
\author{}
\date{}

\begin{document}
\maketitle
\section*{Format specifiers}

\begin{tabular}{ |p{2cm}|
                 p{\dimexpr\textwidth-6cm-6\tabcolsep-4\arrayrulewidth\relax}|
                 p{4cm}| }
  \hline
  \texttt{\%s} & \mintinline{c}{printf("Hello \%s", "World");} & \texttt{Hello World} \\
  \hline
  \texttt{\%d}  & \mintinline{c}{printf("\%d cats", 5);} & \texttt{5 cats} \\
  \hline
\end{tabular}

\end{document}

enter image description here

1
  • Thanks for this! Just a quick explanation for others, since I personally had to stare at this for a while to get what this is doing. The idea is to not use tabularx but tabular instead, since tabularx doesn't work with minted, but tabular works fine. The solution basically presents a way to simulate the X column type in a plain tabular environment. Feb 22, 2017 at 11:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .