在显示块旁边的图像时,我遇到了段落缩进问题lstlisting
。我在线使用 Overleaf(之前发现了几个奇怪的怪癖)。下面是 MWE。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{wrapfig}
\usepackage{listings}
\usepackage{geometry}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{lipsum}
\geometry{letterpaper, portrait, margin=1in}
\lstset{
basicstyle=\ttfamily,
columns=fullflexible,
keepspaces=true
}
\begin{document}
\doublespacing
\lipsum[1]
\begin{wrapfigure}{l}{0.5\textwidth}
\centering
\includegraphics[width=0.48\textwidth]{He3Defect.png}
\caption{Amplitudes of the 3-component OP components}
\end{wrapfigure}
\begin{lstlisting}
NOTICE: using acceleration to solve.
Building problem...done
time: 0 second(s).
solving...
Solver: successfully built
time: 0 seconds.
estimated: 21% done
Found solution:
iterations = 42
relative error = 7.61862e-07
time: 11 second(s).
\end{lstlisting}
\subsection{Free Energy}
Found a converging value for the free energy in 1 dimension.
The free energy calculations for 2 dimensions have not yet been correctly coded.
\lipsum[1]
\newpage
\section{Analysis}
The program will often converge to the correct solution in a reasonably small amount of time.
The possible causes of error were observed to come from poor choices of the relaxation parameter, too small of an iteration limit, poor initial guess, or a bad combination of step size and domain.
The result of the 1-dimensional free energy integral suggests...
The code has not yet been written to model neither the stripe phase nor the polka-dot phase.
\lipsum[2]
\end{document}
以下是部分结果文档:
看起来好像图像很高,但我已经证实事实并非如此;额外的空间可以跨越到新的页面上,并影响其之后的所有页面
我读到过这\lipsum
也可能导致一些奇怪的事情(包裹图的问题),但我放在同一区域的任何文本都会产生相同的效果(因此我只是\lipsum
为了简洁而使用)。我还尝试了其他几个建议(文本中的换行和换行问题,包装图后缩进错误,如何让文字环绕图形?, 和包裹图后文本宽度错误),但没有运气。
在页面顶部或底部附近添加环绕图时要小心,因为这通常会导致难以或几乎无法解决的不良影响。不建议尝试将环绕图与方程式或分段标题一起使用。它们也不能用于列表,例如 itemize 和 enumerate 环境。
会lstlisting
以同样的方式产生影响吗?
关于如何修复它有什么想法吗?
答案1
这显示了如何使用 paracol 来实现这一点。它非常强大,但您必须手动拆分段落。只需让 paracol 运行一段时间,然后看看您希望在哪里进行拆分。
需要使用 [h] 选项来在顶部添加间隙。我提前添加了分割线只是为了展示如何完成。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{paracol}
\usepackage{listings}
\usepackage{geometry}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{lipsum}
\geometry{letterpaper, portrait, margin=1in}
\lstset{
basicstyle=\ttfamily,
columns=fullflexible,
keepspaces=true
}
% used to manually split paagraphs
\newsavebox{\textbox}
\newcommand{\splitpar}[2][\textwidth]{% #1 = width of column (optional), #2 = rest of paragraph after split
\unskip\strut{\parfillskip=0pt\parskip=0pt\par}%
\global\setbox\textbox=\vbox{\hsize=#1\relax\noindent\strut #2\strut}}
\newcommand{\continuepar}{\unvbox\textbox}
\begin{document}
\doublespacing
\lipsum[1]
\begin{paracol}{2}
\begin{figure}[ht]
\centering
\includegraphics[width=\linewidth, height=3.9in]{example-image}
\caption{Amplitudes of the 3-component OP components}
\end{figure}
\switchcolumn
\begin{lstlisting}
NOTICE: using acceleration to solve.
Building problem...done
time: 0 second(s).
solving...
Solver: successfully built
time: 0 seconds.
estimated: 21% done
Found solution:
iterations = 42
relative error = 7.61862e-07
time: 11 second(s).
\end{lstlisting}
\subsection{Free Energy}
Found a converging value for the free energy in 1 dimension.
The free energy calculations for 2 dimensions have \splitpar{not yet been correctly coded.}
\end{paracol}
\continuepar
\lipsum[1]
\newpage
\section{Analysis}
The program will often converge to the correct solution in a reasonably small amount of time.
The possible causes of error were observed to come from poor choices of the relaxation parameter, too small of an iteration limit, poor initial guess, or a bad combination of step size and domain.
The result of the 1-dimensional free energy integral suggests...
The code has not yet been written to model neither the stripe phase nor the polka-dot phase.
\lipsum[2]
\end{document}