我正在尝试创建一个视觉上更具吸引力的图形,看起来像下面的 MWE 的输出。
\documentclass[a4paper]{book}
\usepackage[a4paper]{geometry}
\usepackage{kantlipsum}
\usepackage{tikz}
\usepackage{caption}
\newcommand{\CustomFigure}[3][.4\textwidth]
{
\stepcounter{figure}
%\captionof{figure}[The caption.]{}
\begin{tikzpicture}
\draw (0,0) node(origin) {};
%rectangle (.4\textwidth,40mm);
\draw (origin.west) +(4pt,-8pt) node(caporg){};
\draw [blue, fill=blue] (caporg.south) +(0.0,0.0) -- +(0.09,0.18) -- +(0.18,0) node (arroweast){} -- cycle;
\draw [font=\sffamily\bfseries,blue] (arroweast.east) +(-2pt,+10pt) node[anchor=north west](caption) { Figure \thefigure};
\draw [font=\sffamily,black,text justified, text width=#1] (caporg.south west) +(-1pt,-2pt) node[anchor=north west](description)
{
\mdseries #3
};
\node[anchor=south west,inner sep=0pt] (image) (origin.north west)
{\includegraphics[width=.4\textwidth]{#2}};
\label{fig:NFb}
\end{tikzpicture}
} % \CustomFigure ENDS
\begin{document}
\newgeometry{top=3cm,bottom=3cm,left=1cm,right=1cm,headsep=10pt}
\kant[7]
Some more lipsum.\newline
\begin{figure}
\begin{center}
\includegraphics[width=.4\textwidth]{example-image-a};
\caption{Just a figure.}
\label{fig:NFa}
\end{center}
\end{figure}
\CustomFigure{example-image-b}{\textbf{Header text.} The crazy monkey jumped over the sleeping lion. He met quick brown fox from his own lipsum.}
See figures '\ref{fig:NFa}' and '\ref{fig:NFb}' for details.
\newpage
\listoffigures
\end{document}
'example-image-a' 像往常一样是一个图形。当然可以。
现在,“CustomImage”的输出产生了所需的视觉效果,但图形列表却被搞乱了。它只显示“真实”图形,而不显示自定义图形。(顺便说一句,CustomFigure 不是一个环境,因为它不会绘制文本中的多个字符。)
我以为可以通过添加一个来解决这个问题\captionof{figure}[The caption.]{}
(它确实可以解决这个问题),但这样一来标题本身也会被放置。有没有办法只设置 \thefigure(带步进计数器的步进图形)的标题而不使用 captionof?
图表列表当然必须显示“隐藏”标题的内容。
还是我需要\listoffigures
自己重新实现?
提前谢谢了。
答案1
由于既不\caption
想要\captionof
/使用,也没有命令会将任何内容写入文件.lof
-\CustomFigure
不会对.lof
文件进行任何输入。
这些必须手动完成,\addcontentsline{lof}{figure}{\protect\numberline{\thefigure}#4}
其中#4
标题文本来自可选的第 4 个参数,#3
如果未指定则为默认参数。(参见第 3 种用法)。
\refstepcounter
David Carlisle 已经提出了用法。
\documentclass[a4paper]{book}
\usepackage[a4paper]{geometry}
\usepackage{kantlipsum}
\usepackage{tikz}
\usepackage{xparse}
\usepackage{caption}
\NewDocumentCommand{\CustomFigure}{O{.4\textwidth}+m+m+O{#3}}{%
\refstepcounter{figure}
%\captionof{figure}[The caption.]{}
\begin{tikzpicture}
\draw (0,0) node(origin) {};
%rectangle (.4\textwidth,40mm);
\draw (origin.west) +(4pt,-8pt) node(caporg){};
\draw [blue, fill=blue] (caporg.south) +(0.0,0.0) -- +(0.09,0.18) -- +(0.18,0) node (arroweast){} -- cycle;
\draw [font=\sffamily\bfseries,blue] (arroweast.east) +(-2pt,+10pt) node[anchor=north west](caption) { Figure \thefigure};
\draw [font=\sffamily,black,text justified, text width=#1] (caporg.south west) +(-1pt,-2pt) node[anchor=north west](description)
{
\mdseries #3%
\addcontentsline{lof}{figure}{\protect\numberline{\thefigure}#4}%
};
\node[anchor=south west,inner sep=0pt] (image) (origin.north west)
{\includegraphics[width=.4\textwidth]{#2}};
\end{tikzpicture}
} % \CustomFigure ENDS
\begin{document}
\newgeometry{top=3cm,bottom=3cm,left=1cm,right=1cm,headsep=10pt}
\kant[7]
Some more lipsum.\newline
\begin{figure}
\begin{center}
\includegraphics[width=.4\textwidth]{example-image-a};
\caption{Just a figure.}
\label{fig:NFa}
\end{center}
\end{figure}
\CustomFigure{example-image-b}{\label{fig:NFb}\textbf{Header text.} The crazy monkey jumped over the sleeping lion. He met quick brown fox from his own lipsum. }
\CustomFigure{example-image-b}{\label{fig:NFc}\textbf{Header text.} The crazy monkey jumped over the sleeping lion. He met quick brown fox from his own lipsum.}[And some shorter Text]
See figures '\ref{fig:NFa}' and '\ref{fig:NFb}' for details.
\listoffigures
\end{document}
不带版本\NewDocumentCommand
\documentclass[a4paper]{book}
\usepackage[a4paper]{geometry}
\usepackage{kantlipsum}
\usepackage{tikz}
\usepackage{caption}
\newcommand{\CustomFigure}[3][0.4\textwidth]{%
\refstepcounter{figure}
\begin{tikzpicture}
\draw (0,0) node(origin) {};
%rectangle (.4\textwidth,40mm);
\draw (origin.west) +(4pt,-8pt) node(caporg){};
\draw [blue, fill=blue] (caporg.south) +(0.0,0.0) -- +(0.09,0.18) -- +(0.18,0) node (arroweast){} -- cycle;
\draw [font=\sffamily\bfseries,blue] (arroweast.east) +(-2pt,+10pt) node[anchor=north west](caption) { Figure \thefigure};
\draw [font=\sffamily,black,text justified, text width=#1] (caporg.south west) +(-1pt,-2pt) node[anchor=north west](description)
{
\mdseries #3%
\addcontentsline{lof}{figure}{\protect\numberline{\thefigure}#3}%
};
\node[anchor=south west,inner sep=0pt] (image) (origin.north west)
{\includegraphics[width=.4\textwidth]{#2}};
\end{tikzpicture}
} % \CustomFigure ENDS
\begin{document}
\newgeometry{top=3cm,bottom=3cm,left=1cm,right=1cm,headsep=10pt}
\kant[7]
Some more lipsum.\newline
\begin{figure}
\begin{center}
\includegraphics[width=.4\textwidth]{example-image-a};
\caption{Just a figure.}
\label{fig:NFa}
\end{center}
\end{figure}
\CustomFigure{example-image-b}{\label{fig:NFb}\textbf{Header text.} The crazy monkey jumped over the sleeping lion. He met quick brown fox from his own lipsum. }
\CustomFigure{example-image-b}{\label{fig:NFc}\textbf{Header text.} The crazy monkey jumped over the sleeping lion. He met quick brown fox from his own lipsum.}
See figures '\ref{fig:NFa}' and '\ref{fig:NFb}' for details.
\listoffigures
\end{document}