我有一个项目列表,其中一些项目包含图形、列表等。如何让这些环境忽略环境中的额外缩进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
包。