这是这个帖子,那里给出的解决方案 - 将三个列表放在一行中,延伸到页面边缘之外(在这种情况下是可取的) - 当以框架形式的样式添加到列表中时会中断,例如:
\begin{lstlisting}[frame=single, caption={a}]
是否有可能在不涉及复杂的 tikz 绘图的情况下解决这个问题?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{listings}
\usepackage{tabularx}
\usepackage{showframe}% only to show the page margins
\usepackage{mwe}% only to have some blind text
\begin{document}
\blindtext
\begin{figure}
\hspace*{-100pt}% to go to the left of the left margin
\begin{tabular}{ccc}
\begin{minipage}[t]{.3\paperwidth}% increase the width according to your needs
\begin{lstlisting}[frame=single, caption={a}]
for (i in 1..n):
. . .
lock.lock()
shared++
lock.unlock()
. . .
\end{lstlisting}
\end{minipage} &
\begin{minipage}[t]{.3\paperwidth}
\begin{lstlisting}[caption={b}]
for (i in 1..n):
. . .
lock.lock()
shared++
lock.unlock()
. . .
\end{lstlisting}
\end{minipage} &
\begin{minipage}[t]{.3\paperwidth}
\begin{lstlisting}[caption={c}]
for (i in 1..n):
. . .
lock.lock()
shared++
lock.unlock()
. . .
\end{lstlisting}
\end{minipage}\\
\end{tabular}
\end{figure}
\end{document}
答案1
添加\lstset{frame=single}
到您的序言中,也许您必须更改\hspace*{}
。
梅威瑟:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{listings}
\usepackage{tabularx}
\usepackage{showframe}% only to show the page margins
\usepackage{mwe}% only to have some blind text
\lstset{frame=single}
\begin{document}
\blindtext
\begin{figure}
\hspace*{-120pt}% to go to the left of the left margin
\begin{tabular}{ccc}
\begin{minipage}[t]{.3\paperwidth}% increase the width according to your needs
\begin{lstlisting}[caption={a}]
for (i in 1..n):
. . .
lock.lock()
shared++
lock.unlock()
. . .
\end{lstlisting}
\end{minipage} &
\begin{minipage}[t]{.3\paperwidth}
\begin{lstlisting}[caption={b}]
for (i in 1..n):
. . .
lock.lock()
shared++
lock.unlock()
. . .
\end{lstlisting}
\end{minipage} &
\begin{minipage}[t]{.3\paperwidth}
\begin{lstlisting}[caption={c}]
for (i in 1..n):
. . .
lock.lock()
shared++
lock.unlock()
. . .
\end{lstlisting}
\end{minipage}\\
\end{tabular}
\end{figure}
\end{document}