我想在侧面带标题的图形周围绘制框架。我已经使用sidecap
包和\begin{SCfigure} \end{SCfigure}
环境创建了侧面带标题的图形。我试过mdframed
包,但它不起作用。我也试过了,\fbox{}
但框架只出现在 graphicx 周围,而不是在标题周围。我在谷歌上搜索了很多,但找不到合适的答案。
以下示例有效
\documentclass{report}
\usepackage[demo]{graphicx}
\usepackage{sidecap}
\usepackage{mdframed}
\begin{document}
\begin{figure}
\begin{mdframed}
\centering
\includegraphics{image}
\caption{A figure and its caption framed}
\label{fig:test}
\end{mdframed}
\end{figure}
\begin{SCfigure}
\includegraphics{image}
\caption{A figure and its caption framed}
\label{fig:test}
\end{SCfigure}
\end{document}
但下面的例子不起作用
\documentclass{report}
\usepackage[demo]{graphicx}
\usepackage{sidecap}
\usepackage{mdframed}
\begin{document}
\begin{figure}
\begin{mdframed}
\centering
\includegraphics{image}
\caption{A figure and its caption framed}
\label{fig:test}
\end{mdframed}
\end{figure}
\begin{SCfigure}
\begin{mdframed}
\includegraphics{image}
\caption{A figure and its caption framed}
\label{fig:test}
\end{mdframed}
\end{SCfigure}
\end{document}
给出以下错误Something's wrong--perhaps a missing \item. \includegraphics
答案1
如果你愿意切换到另一个包,那么强大的floatrow
软件包BOXED
针对这些情况具有以下样式:
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{floatrow}
\begin{document}
{
\floatsetup{style=BOXED,capposition=beside,capbesideposition={top,left}}
\begin{figure}
\includegraphics{image}
\caption{A figure and its caption framed}
\label{fig:test}
\end{figure}
}
\end{document}
选项demo
只是graphicx
用黑色矩形替换实际图形;不是在实际文档中使用该选项。
答案2
问题不是与 相关的mdframed
。它基于 的实现,sidecap
如下例所示:
\setcounter{errorcontextlines}{999}
\documentclass{report}
\usepackage[demo]{graphicx}
\usepackage{sidecap}
\begin{document}
\begin{SCfigure}
\begin{itemize}
\item foo
\end{itemize}
\caption{A figure and its caption framed}
\label{fig:test}
\end{SCfigure}
\end{document}
问题是sidecap
将材料保存在 中hbox
。因此,每个垂直材料(如itemize
或 )list
都会导致错误。要处理此类垂直材料,您必须指定 minipage 或类似的东西。
要使用,mdframed
您必须修补的输出命令sidecap
。
下面是一个例子:
\documentclass{report}
\usepackage[demo]{graphicx}
\usepackage{xcolor}
\usepackage{sidecap}
\usepackage[framemethod=tikz]{mdframed}
\mdfdefinestyle{sidefig}{middlelinewidth=2pt,backgroundcolor=lightgray,roundcorner=8pt}
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\endSC@FLOAT}{\@FLOAT{\SC@captype}}{\@FLOAT{\SC@captype}\begin{mdframed}[style=sidefig]}{}{}
\xpatchcmd{\endSC@FLOAT}{\end@FLOAT}{\end{mdframed}\end@FLOAT}{}{}
\makeatother
\begin{document}
\begin{SCfigure}
\includegraphics{image}
\caption{A figure and its caption framed}
\label{fig:test}
\end{SCfigure}
\end{document}