忽略图表、列表等的逐项缩进

忽略图表、列表等的逐项缩进

我有一个项目列表,其中一些项目包含图形、列表等。如何让这些环境忽略环境中的额外缩进itemize

我的代码如下:

\begin{itemize}
    \item
     Bla bla
     \begin{figure} 
        % indent should be ignored here!
        ... 
     \end{figure}
    \item
     More bla bla
     \begin{lstlisting} 
        // indent should be ignored here!
        ... 
     \end{lstlisting}
\end{itemize}

答案1

两个选项:

  • 中断itemize图像和列表。

  • \hbox对图像和列表使用(这需要先前将列表装箱):

显示两个选项的代码:

\documentclass{article}
\usepackage{listings}
\usepackage{graphicx}

\newsavebox\mybox

\begin{document}

\begin{lrbox}{\mybox}
\begin{lstlisting} 
// indent is ignored here!
code test text
\end{lstlisting}
\end{lrbox}

Some test text for the example and some more words test text for the example and some more words test text for the example and some more words test text for the example and some more words test text for the example and some more words
\begin{itemize}
    \item
     Bla bla
\end{itemize}     
\includegraphics[width=\textwidth,height=2cm]{example-image-a}
\begin{itemize}
    \item
     More bla bla
\end{itemize}     
\begin{lstlisting} 
// indent is ignored here!
code test text
\end{lstlisting}
Some test text for the example and some more words test text for the example and some more words test text for the example and some more words test text for the example and some more words test text for the example and some more words
\begin{itemize}
    \item
     Bla bla\par\medskip

    \hbox{\includegraphics[width=\textwidth,height=2cm]{example-image-a}}
    \item
     More bla bla\par\medskip

     \hbox{\usebox\mybox}
\end{itemize}

\end{document}

在此处输入图片描述

当然,最好不要figure对图像使用浮动,否则图形可能会浮动到您希望它出现的位置(在itemize精确的位置内)。如果您需要图形的一些标题,请\captionof使用capt-of或者caption包。

相关内容