marginpar 中的图形垂直放置

marginpar 中的图形垂直放置

我想通过 将小图形放入边距中\marginpar。图形的顶部应与它们引用的文本行的顶部对齐。我发现这里有建议将 放入\vskip0ptmarginpar,这似乎有点用,但位置仍然不完美。在良好的 LaTeX 样式中,我希望有一个可以自动运行的解决方案,即无需手动调整每个图形的像素,并且功能强大(字体大小、线条分布等)。

在以下 MWE 中,问题在 1.2.1 和 1.2.2 中尤为明显

\documentclass[twoside]{article}

\usepackage[demo]{graphicx}

\begin{document}
\section{Graphical note}
\subsection{With new paragraph}
\subsubsection{Text blocks}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.

% \leavevmode% makes things worse
%% \vksip3pt seems to be correct
\marginpar{\vskip0pt\includegraphics[width=4cm,height=1cm]{test}}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\subsubsection{Equation ending}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.
\begin{equation}
  a = b
\end{equation}%

% \leavevmode% makes things worse
%% seems OK
\marginpar{\vskip0pt\includegraphics[width=4cm,height=1cm]{test}}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\subsection{Without new paragraph}
\subsubsection{Text blocks}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.
%% \vksip-7pt seems to be correct
\marginpar{\vskip0pt\includegraphics[width=4cm,height=1cm]{test}}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\subsubsection{Equation ending}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.
\begin{equation}
  a = b
\end{equation}%
%% \vksip-7pt seems to be correct
\marginpar{\vskip0pt\includegraphics[width=4cm,height=1cm]{test}}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\clearpage
\section{With textual note}
The following four cases work fine.
\subsection{With new paragraph}
\subsubsection{Text blocks}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.

\leavevmode%
\marginpar{Baz baz baz baz baz}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\subsubsection{Equation ending}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.
\begin{equation}
  a = b
\end{equation}

\leavevmode%
\marginpar{Baz baz baz baz baz}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\subsection{Without new paragraph}
\subsubsection{Text blocks}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.
\marginpar{Baz baz baz baz baz}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\subsubsection{Equation ending}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.
\begin{equation}
  a = b
\end{equation}
\marginpar{Baz baz baz baz baz}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\end{document}

示例输出

答案1

您可以更改.7乘数\baselineskip以进行微调。请注意,\rule在开头\ffig是一种人为的方式,以确保开始新的段落。如果\marginpar在段落的最开头调用,它实际上会附加到前一段的最后一行。由于您曾多次想要将放在\marginpar段落开头,因此需要这样做。此外,\heightMartin Scharrer 在内联图像的垂直对齐

\documentclass[twoside]{article}

\usepackage[demo]{graphicx}

\newcommand\ffig[1]{%
  \rule{0ex}{1ex}%
  \marginpar{\smash{\raisebox{.7\baselineskip}{\raisebox{-\height}{#1}}}}%
}

\begin{document}
\section{Graphical note}
\subsection{With new paragraph}
\subsubsection{Text blocks}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.

\ffig{\includegraphics[width=4cm,height=1cm]{test}}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\subsubsection{Equation ending}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.
\begin{equation}
  a = b
\end{equation}%

\ffig{\includegraphics[width=4cm,height=1cm]{test}}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\subsection{Without new paragraph}
\subsubsection{Text blocks}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.
\ffig{\includegraphics[width=4cm,height=1cm]{test}}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\subsubsection{Equation ending}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.
\begin{equation}
  a = b
\end{equation}%
\ffig{\includegraphics[width=4cm,height=1cm]{test}}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\clearpage
\section{With textual note}
The following four cases work fine.
\subsection{With new paragraph}
\subsubsection{Text blocks}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.

\leavevmode%
\marginpar{Baz baz baz baz baz}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\subsubsection{Equation ending}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.
\begin{equation}
  a = b
\end{equation}

\leavevmode%
\marginpar{Baz baz baz baz baz}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\subsection{Without new paragraph}
\subsubsection{Text blocks}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.
\marginpar{Baz baz baz baz baz}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\subsubsection{Equation ending}

Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo.
\begin{equation}
  a = b
\end{equation}
\marginpar{Baz baz baz baz baz}%
Bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar.

\end{document}

在此处输入图片描述

相关内容