我在图形下方添加了一条线,使其更加美观。我无法将线的长度与图形的长度相匹配。
这是 MWE。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\newcommand{\decoRule}{\rule{\textwidth}{.4pt}} % New command for a rule to be used under figures
\begin{document}
Example of how I define and use DecoRule.
\begin{figure}[tbp]
\centering
\includegraphics[scale=0.9]{cover}
\decoRule
\caption[Cover]{This is a cover.}
\end{figure}
\end{document}
答案1
您可以\widthof
从 calc 包中使用:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{calc}
\newcommand{\decoRule}[1]{\rule{#1}{.4pt}} % New command for a rule to be used under figures
\usepackage{mwe}
\begin{document}
Example of how I define and use DecoRule.
\begin{figure}[tbp]
\centering
\includegraphics[scale=0.7]{example-image-a}
\decoRule{\widthof{\includegraphics[scale=0.7]{example-image-a}}}
\caption[Cover]{This is a cover.}
\end{figure}
\end{document}
我添加了mwe
,以便在没有您的具体数字的情况下我可以进行编译。
最有效的可能是创建一个新命令来包装整个内容,而不仅仅是将 decoline 设为命令并重新输入图形。
答案2
您需要将规则的长度与图形宽度结合起来。这里是通过以下方式完成的,\setbox
但您也可以使用\settowidth
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
%\newcommand{\decoRule}{\rule{\textwidth}{.4pt}} % New command for a rule to be used under figures
\newcommand\decoImage[2][]{%
\setbox0\hbox{\includegraphics[#1]{#2}}
\parbox{\wd0}{%
\copy0
\hrulefill
}
}
\begin{document}
Text
\begin{figure}[tbp]
\centering
\decoImage[scale=0.4,angle=30]{example-image-a}
\caption[Cover]{This is a cover.}
\end{figure}
\end{document}