我想在文档中添加一条线来区分图形和文本。我找到了一种添加线条的方法,但是我希望它的长度与标题的长度相同而不是\linewidth
。但是,当我将其设置为一小部分时,它\linewidth
会自动从左边缘开始,而我无法将其精确地放在标题下方。
这是我的代码:
\documentclass{memoir}
\usepackage{lipsum} %Needed to create dummy text
\usepackage{graphicx}
\newcommand{\botfigrule}{
\vspace*{5pt}{\hrule height0.8pt width 0.9\linewidth}\vspace{1pt}}
% My caption style
\newcommand{\mycaption}[2][\@empty]{
\captionnamefont{\scshape}
\changecaptionwidth
\captionwidth{0.9\linewidth}
\captiondelim{.\:}
\captionstyle[\centering]{}
\setlength{\belowcaptionskip}{10pt}
\ifx \@empty#1 \caption{#2}\else \caption[#1]{#2}
}
\begin{document}
\lipsum[2]
\begin{figure}[h!]
\centering
\includegraphics[width=0.4\textwidth]{images/example.jpeg}
\mycaption{ \lipsum[1]}
\botfigrule
\label{fig:gr_lattice}
\end{figure}
\lipsum[2]
\end{document}
答案1
手册memoir
中有格线图形的示例(请参阅文档第 173 页)。使用以下命令即可\botfigrule
:
\newcommand{\botfigrule}{\rule{.9\linewidth}{0.4pt}\vspace{\onelineskip}}
这是一个完整的例子。
\documentclass{memoir}
\usepackage{lipsum} %Needed to create dummy text
\usepackage[draft]{graphicx}
\newcommand{\botfigrule}{\rule{.9\linewidth}{0.4pt}\vspace{\onelineskip}}
% My caption style
\newcommand{\mycaption}[2][\@empty]{
\captionnamefont{\scshape}
\changecaptionwidth
\captionwidth{0.9\linewidth}
\captiondelim{.\:}
\captionstyle[\centering]{}
\setlength{\belowcaptionskip}{10pt}
\ifx \@empty#1 \caption{#2}\else \caption[#1]{#2}
}
\begin{document}
\lipsum[2]
\begin{figure}[h!]
\centering
\includegraphics[width=0.4\textwidth]{images/example.jpeg}
\mycaption{ \lipsum[1]}
\botfigrule
\label{fig:gr_lattice}
\end{figure}
\lipsum[2]
\end{document}
答案2
这是我的解决方案
\documentclass{article}
\newcommand{\botfigrule}{
\vspace*{5pt}{\hrule height0.8pt width \textwidth}\vspace{1pt}}
\usepackage{graphicx}
\begin{document}
\begin{figure}[t]
\centering
\includegraphics[width=\textwidth]{potatoes.jpg}
\caption{ very very very very very very very very very very
very very very very very very very very very very
very very very very very very very very very very
very very very very very very very very very very
long text }
\label{fig:try}
\botfigrule
\end{figure}
\end{document}
我只是在图形环境中使用了 \textwidth 而不是 0.9\linewidth 和 \centering
编辑:
\documentclass{memoir}
\usepackage{lipsum} %Needed to create dummy text
\usepackage{graphicx}
\newcommand{\botfigrule}{
\vspace*{5pt}
\parbox{0.5\textwidth}{
{\hrule height0.8pt width 0.5\textwidth}
}}
% My caption style
\newcommand{\mycaption}[2][\@empty]{
\captionnamefont{\scshape}
\changecaptionwidth
\captionwidth{0.9\linewidth}
\captiondelim{.\:}
\captionstyle[\centering]{}
\setlength{\belowcaptionskip}{10pt}
\ifx \@empty#1 \caption{#2}\else \caption[#1]{#2}
}
\begin{document}
\lipsum[2]
\begin{figure}[h!]
\centering
\includegraphics[width=0.4\textwidth]{potatoes.jpg}
\mycaption{ \lipsum[1]}
\botfigrule
\label{fig:gr_lattice}
\end{figure}
\lipsum[2]
\end{document}