如何在缩进列表的中间插入整列宽度的文本块

如何在缩进列表的中间插入整列宽度的文本块

我正在尝试在缩进和嵌套列表项中间插入一段设置为全行宽的文本。我问了一个一般性问题,但在我的例子中它涉及到包listings。我需要的是这样的:

\item ....

\begin{fullwidth}
\begin{lstlisting)
blah blah too long for indented width but fits in full column width
\end{lstlisting}
\end{fullwidth}

blah blah blah

\item ...

figure我有一个使用环境加\FloatBlock(来自)的权宜之计memoir,但我并不热衷。

还有其他更好的想法吗?

答案1

解决方案来自于包本身:您可以在环境中listings使用该选项。resetmargins=truelstlisting

我创建了几个示例只是为了好玩。你可能想要的是第 6 个。

\documentclass{article}

\usepackage{listings}
\usepackage{fullwidth}% if your really need the fullwidth environment

\begin{document}
    Inside the \verb|itemize| environment:
    \begin{itemize}
        \item example 1

        blah blah too long for indented width but fits in full column width

        \item example 2
        \begin{flushleft}
            blah blah too long for indented width but fits in full column width
        \end{flushleft}

        \item example 3
        \begin{fullwidth}
            blah blah too long for indented width but fits in full column width
        \end{fullwidth}

        \item example 4
        \begin{fullwidth}[skipabove=0pt, skipbelow=0pt]
            blah blah too long for indented width but fits in full column width
        \end{fullwidth}

        \item example 5
\begin{lstlisting}
blah blah too long for indented width but fits in full column width
\end{lstlisting}

        \item example 6 (THIS IS THE ONE)
\begin{lstlisting}[resetmargins=true]
blah blah too long for indented width but fits in full column width
\end{lstlisting}

        \item example 7
        blah blah too long for indented width but fits in full column width
    \end{itemize}

    Outside the \verb|itemize| environment:
\begin{lstlisting}
blah blah too long for indented width but fits in full column width
\end{lstlisting}
\end{document}

结果如下: 在此处输入图片描述

相关内容