如何在itemize
环境中插入图形,使其位于项目中心,而不是整个文本宽度?我figure
首先在环境中尝试,但图形太靠左了。然后我在环境中尝试center
,但标题(而不是图形)出现了同样的问题。
\documentclass[12pt]{article}
\usepackage{caption}
\usepackage{tikz}
\usepackage{blindtext}
\begin{document}
\begin{itemize}
\item \blindtext
\begin{center}
\captionsetup{type=figure}
\begin{tikzpicture}
\clip(-5.686675053232457,-3.16893917565149) rectangle (5.579414724686105,0.6921754200738994);
\draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105]plot(\x,{(--4.514220105043796-1.8219356725415592*\x)/1.894960446786564});
\draw [line width=1.2pt,dash pattern=on 4pt off 4pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--1.6188066144426525-1.0979714604086213*\x)/-0.3751399196759637});
\draw [line width=1.2pt,dash pattern=on 4pt off 4pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--11.463481791986391--1.2426776436313691*\x)/-5.670646727250561});
\draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--0.4039090361160175--0.6586822831185679*\x)/-0.27723191082856635});
\draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(-2.9955647165449215--0.8716146065783191*\x)/4.89799733746727});
\end{tikzpicture}
\caption{blablablablablablablablablablablablablablablablablablabla}
\end{center}
\end{itemize}
\end{document}
更新:我认为这可能是一个解决方案:
\begin{itemize}
\item \blindtext
\bigbreak
\begin{minipage}{\linewidth}
\centering
\begin{tikzpicture}
\clip(-5.686675053232457,-3.16893917565149) rectangle (5.579414724686105,0.6921754200738994);
\draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105]plot(\x,{(--4.514220105043796-1.8219356725415592*\x)/1.894960446786564});
\draw [line width=1.2pt,dash pattern=on 4pt off 4pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--1.6188066144426525-1.0979714604086213*\x)/-0.3751399196759637});
\draw [line width=1.2pt,dash pattern=on 4pt off 4pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--11.463481791986391--1.2426776436313691*\x)/-5.670646727250561});
\draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--0.4039090361160175--0.6586822831185679*\x)/-0.27723191082856635});
\draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(-2.9955647165449215--0.8716146065783191*\x)/4.89799733746727});
\end{tikzpicture}
\captionsetup{type=figure}
\caption{blablablablablablablablablablablablablablablabla}
\end{minipage}
\bigbreak
\end{itemize}
答案1
在列表环境中提供adjustbox
了许多功能,例如itemize
。
传递以下键可得到adjustbox
您所描述的内容:
- 位于线宽中央的图形:
center=\linewidth
- 前后间距(
bigskip
替换):margin=0ex 2ex 0ex 2ex
- 将其标识
tikzpicture
为图形,但不要使其浮动:nofloat=figure
- 提供图形标题:
caption=This figure does not float. It is placed between the two items
- 添加装饰框:
cfbox=blue 1pt
为了回答 OP 的问题,提供了第二个例子。
- 被
tikzpicture
视为浮动图形:figure=htb
,其中 htb 是图形的放置选项。 - 标题标记为:
\label{fig:MyFigure}
。 - 标题移至图的顶部:
captionabove={This figure floats. Its placement is determined by page content and the
figure=htbsettings}
。 - 添加了包以在文本中的位置( )和图形标题
hyperref
之间创建链接。\ref{fig:MyFigure}
我遇到了一个问题,第二个示例中的标题不再限制在条目的行宽内。这是更改nofloat=figure
为 的结果figure=htp
。我只能通过一个 hack 来解决这个问题,即:
- 已加载
enumitem
并caption
打包 - 添加
\captionsetup{margin=0.5cm}
- 添加
[leftmargin=*]
我确信这可以得到改进,因为我只是不断尝试,直到成功为止。
以下是每个示例的结果。请注意,第二个示例仍将图形放置在两个项目之间,因为它h
被用作放置选项,并且它与页面内容相适应。
尝试改为\Blindtext[1][2]
。\Blindtext[3][2]
页面上没有足够的空间放置图形,因此图形会浮动到下一页,而文本仍保留在第一页。
这是每个示例的输出:
这是代码:
\documentclass[a4paper,11pt]{article}
\usepackage{tikz}
\usepackage[english]{babel} % for pangram from blindtext package
\usepackage[pangram]{blindtext}
\usepackage{adjustbox}
\usepackage{caption}
\usepackage{enumitem}
\usepackage{hyperref}
\begin{document}
\begin{itemize}%[leftmargin=*] % Dont use leftmargin setting. It upsets the caption alignment
\item[***] \textbf{Example 1}
\item \Blindtext[1][2]
\begin{adjustbox}{
cfbox=blue 1pt, % draw a box around the picture
center=\linewidth, % center the picture in the with of the line
margin=0ex 2ex 0ex 2ex, % add some space above and below the figure
caption=This figure does not float. It is placed between the two items., % give the figure caption
nofloat=figure % this is a non-floating figure
}
\begin{tikzpicture}
\clip(-5.686675053232457,-3.16893917565149) rectangle (5.579414724686105,0.6921754200738994);
\draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105]plot(\x,{(--4.514220105043796-1.8219356725415592*\x)/1.894960446786564});
\draw [line width=1.2pt,dash pattern=on 4pt off 4pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--1.6188066144426525-1.0979714604086213*\x)/-0.3751399196759637});
\draw [line width=1.2pt,dash pattern=on 4pt off 4pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--11.463481791986391--1.2426776436313691*\x)/-5.670646727250561});
\draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--0.4039090361160175--0.6586822831185679*\x)/-0.27723191082856635});
\draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(-2.9955647165449215--0.8716146065783191*\x)/4.89799733746727});
\end{tikzpicture}
\end{adjustbox}
%
\item \Blindtext[1][2]
\end{itemize}
% A new example added with the figure as a float, a label for the figire and a reference to the figure
\begin{itemize}[leftmargin=*] %Add left margin setting to get correct caption alignment
\item[***] \textbf{Example 2}
\item \Blindtext[1][2]
\item This is a reference to Figure \ref{fig:MyFigure}.
\captionsetup{margin=0.5cm}
\begin{adjustbox}{
cfbox=green 1pt, % draw a box around the picture
center=\linewidth, % center the picture in the with of the line
margin=0ex 2ex 0ex 2ex, % add some space above and below the figure
captionabove={This figure floats. Its placement is determined by page content and the figure=htb settings.} \label{fig:MyFigure}, % give the figure caption and a label to link to
figure=htb % this is a floating figure with placement options
}
\begin{tikzpicture}
\clip(-5.686675053232457,-3.16893917565149) rectangle (5.579414724686105,0.6921754200738994);
\draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105]plot(\x,{(--4.514220105043796-1.8219356725415592*\x)/1.894960446786564});
\draw [line width=1.2pt,dash pattern=on 4pt off 4pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--1.6188066144426525-1.0979714604086213*\x)/-0.3751399196759637});
\draw [line width=1.2pt,dash pattern=on 4pt off 4pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--11.463481791986391--1.2426776436313691*\x)/-5.670646727250561});
\draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--0.4039090361160175--0.6586822831185679*\x)/-0.27723191082856635});
\draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(-2.9955647165449215--0.8716146065783191*\x)/4.89799733746727});
\end{tikzpicture}
\end{adjustbox}
%
\item \Blindtext[1][2]
\end{itemize}
\end{document}
答案2
我认为这可能是一个解决方案:
\begin{itemize}
\item \blindtext
\bigbreak
\begin{minipage}{\linewidth}
\centering
\begin{tikzpicture}
\clip(-5.686675053232457,-3.16893917565149) rectangle (5.579414724686105,0.6921754200738994);
\draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105]plot(\x,{(--4.514220105043796-1.8219356725415592*\x)/1.894960446786564});
\draw [line width=1.2pt,dash pattern=on 4pt off 4pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--1.6188066144426525-1.0979714604086213*\x)/-0.3751399196759637});
\draw [line width=1.2pt,dash pattern=on 4pt off 4pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--11.463481791986391--1.2426776436313691*\x)/-5.670646727250561});
\draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--0.4039090361160175--0.6586822831185679*\x)/-0.27723191082856635});
\draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(-2.9955647165449215--0.8716146065783191*\x)/4.89799733746727});
\end{tikzpicture}
\captionsetup{type=figure}
\caption{blablablablablablablablablablablablablablablabla}
\end{minipage}
\bigbreak
\end{itemize}