我正在使用的代码边距浮动和超链接。它运行良好,但是生成的图形没有像下面的标题那样在边距中左对齐。我也尝试\raggedright
了将图形右对齐,左对齐。
平均能量损失
\documentclass{report}
\usepackage{geometry}
\geometry{
showframe=true,
includeheadfoot,
includemp,
marginparwidth=3.5cm,
marginparsep=1.5em,
hmargin={3cm,1.5cm},
vmargin={2cm,2cm},
headsep=2ex,
footskip=3ex
}
%
%https://tex.stackexchange.com/questions/27348/margin-floats-and-hyperlinks
\usepackage{placeins}
\makeatletter
% Margin float environment
\newsavebox{\@tufte@margin@floatbox}
\newenvironment{@tufte@margin@float}[2][-1.2ex]%
{\FloatBarrier% process all floats before this point so the figure/table numbers stay in order.
\begin{lrbox}{\@tufte@margin@floatbox}%
\begin{minipage}{\marginparwidth}%
\def\@captype{#2}%
\hbox{}\vspace*{#1}%
\noindent%
}
{\end{minipage}%
\end{lrbox}%
\marginpar{\usebox{\@tufte@margin@floatbox}}%
}
% Margin figure environment
\newenvironment{marginfigure}[1][-1.2ex]%
{\begin{@tufte@margin@float}[#1]{figure}
}
{\end{@tufte@margin@float}}
% Margin table environment
\newenvironment{margintable}[1][-1.2ex]%
{\begin{@tufte@margin@float}[#1]{table}
}
{\end{@tufte@margin@float}}
\makeatother
\begin{document}
\begin{marginfigure}
%\raggedright
\rule{3cm}{2cm}
\caption{A long caption so that we get at least two lines}
\end{marginfigure}
\end{document}
答案1
marginfigure
和的定义中有一个虚假的空间margintable
:
% Margin figure environment
\newenvironment{marginfigure}[1][-1.2ex]%
{\begin{@tufte@margin@float}[#1]{figure}% <--- added '%'
}
{\end{@tufte@margin@float}}
% Margin table environment
\newenvironment{margintable}[1][-1.2ex]%
{\begin{@tufte@margin@float}[#1]{table}% <--- added '%'
}
{\end{@tufte@margin@float}}
作为参考,请参阅%
行末百分号 ( ) 有什么用?。或者,您可以\ignorespaces
在环境的开头插入一个。