
lstlisting
是否有選項可以在的標題中換行?例如:
\begin{lstlisting}[frame=single, caption=uppertext\\lowertext)]
我嘗試過\\
其他一些解決方案,但它們中的任何一個都有效。
答案1
您可以caption
使用 來設定tabular
。不過,還要設定選修的標題(對於\lstlistoflistings
)沒有斷行tabular
:
\documentclass{article}
\usepackage{listings}
\begin{document}
\lstlistoflistings
\begin{lstlisting}[
frame = single,
caption = {[upper/lower text]%
\begin{tabular}[t]{@{}l@{}}
upper text \\
lower text \\[.5\normalbaselineskip]
\end{tabular}}
]
Hello world
\end{lstlisting}
\end{document}
由於frame
,需要進行一些垂直調整(以 的形式\\[.5\normalbaselineskip]
)。