在每个图形(包括标题)的上方和下方添加一条规则

在每个图形(包括标题)的上方和下方添加一条规则

我有一份包含大量图片的文档,我想修改它们,以便每个图片的上方和下方都有一条水平线,使其与文本区分开来。也就是说,我希望它看起来像这样:

文本.... 文本.... 文本....

文本.... 文本.... 文本....

- - - - - - - - - - - - - - - - % 规则

点击此处

...........

图片标题:blah blah

------------------------------- %另一条规则

文本.... 文本.... 文本....

我知道我可以单独去修改每个图形,但我想知道是否有办法自动对所有图形执行此操作......

答案1

您可以使用float

\documentclass{article}
\usepackage{graphicx}
\usepackage{float}

\makeatletter
\newcommand\fs@tbruled{%
  \def\@fs@cfont{\normalfont}%
  \let\@fs@capt\floatc@plain
  \def\@fs@pre{\hrule\kern2pt}%
  \def\@fs@post{\kern2pt\hrule\relax}%
  \def\@fs@mid{\vspace{\abovecaptionskip}}%
  \let\@fs@iftopcapt\iffalse
}
\makeatother

\floatstyle{tbruled}
\restylefloat{figure}

\begin{document}

Some text before your figure. Some text before your figure. Some text before your figure. 
Some text before your figure.
\begin{figure}[htp]
\centering

\includegraphics{example-image-a}
\caption{My caption}

\end{figure}
Some text after your figure. Some text after your figure. Some text after your figure. 
Some text after your figure.

\end{document}

在此处输入图片描述

让我们看看这些命令的作用:

\def\@fs@cfont{\normalfont}%              The font for the caption label
\let\@fs@capt\floatc@plain %              Use plain style caption
\def\@fs@pre{\hrule\kern2pt}%             The rule at the top
\def\@fs@post{\kern2pt\hrule\relax}%      The rule at the bottom
\def\@fs@mid{\vspace{\abovecaptionskip}}% Material to be inserted before the caption
\let\@fs@iftopcapt\iffalse %              We don't want the caption is moved at the top

如果你想要在顶部规则之后有更多空间,请更改为

\def\@fs@pre{\hrule\kern12pt}%

或任何你认为合适的空间。底部的规则也类似。

答案2

只需创建您自己的环境。

\documentclass{article}
\usepackage{graphicx}
\newenvironment{myfigure}%
    {\begin{figure}[htb]\hrule\vspace{3ex}\centering}%
    {\vspace{3ex}\hrule\end{figure}}

\begin{document}
Some text before your figure. Some text before your figure. Some text before your figure. Some text before your figure.%
\begin{myfigure}
    \includegraphics{example-image-a}
    \caption{My caption}
\end{myfigure}
Some text after your figure. Some text after your figure. Some text after your figure. Some text after your figure.
\end{document}

在此处输入图片描述

相关内容