printf
我正在编写格式字符串的参考表:
\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}
我正在使用进行编译lualatex -shell-escape -synctex=1 -interaction=nonstopmode "printf".tex
,收到的错误是:
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.
...
如果我将\mintinline
移出 tabularx 块,它就可以正常工作。如果我将 minted 的包声明更改为\usepackage[cache=false]{minted}
,它可以工作(很慢),但表格无法正确调整大小,并且代码示例的末尾与下一列重叠:
答案1
tabular
这是按照 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}