将两个小页面(一个带有列表列表,一个不带有列表列表)对齐到顶部?

将两个小页面(一个带有列表列表,一个不带有列表列表)对齐到顶部?

我已经知道两个带有 [t] 的小页面在顶线的基线对齐,而不是在各自的框/容器的顶部对齐;然而,这有些不同:当我使用一个带有一个字母的小型页面和一个带有 lstlisting 的小型页面,并尝试将它们对齐在顶部,如下面的 MWE 所示,我得到了这个(使用lua-visual-debug):

测试02b.png

我真的不明白——是什么把列表小页面向下推,换行符?那是从哪里来的?我怎样才能让这两个项目在顶部对齐(这样列表小页面就A保持在原处 - 列表+小页面垂直向上移动以匹配它)?

顺便说一句,请注意下面的 MWE - 第二个示例,其中有两个带有列表的小页面,可以毫无问题地运行:

\documentclass{article}

%\usepackage{lua-visual-debug}
\usepackage{listings}

\begin{document}

Test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test ...

\begin{minipage}[t]{1em}
A
\end{minipage}
\hfill
\begin{minipage}[t]{\dimexpr\textwidth-2\parindent-2.2em}%
\begin{lstlisting}
sslg kaha kshd kajshd
asl q7ey q[peo [pdv
sdfk a9su qpowie e
asj asy dqoi poai
\end{lstlisting}
\end{minipage}

Test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test ...

% http://tex.stackexchange.com/questions/36712/how-to-place-two-code-/36737
\begin{minipage}[t]{0.45\linewidth}
\begin{lstlisting}[caption={Some XML Caption}]
  .. xml code ...
  .. xml code ...
  .. xml code ...
  .. xml code ...
  .. xml code ...
  .. xml code ...
\end{lstlisting}
\end{minipage}
%
\begin{minipage}[t]{0.45\linewidth}
\begin{lstlisting}[caption={Some Javascript Caption}]
  ... javascript code ...
  ... javascript code ...
  ... javascript code ...
\end{lstlisting}
\end{minipage}

\end{document}

答案1

方法listings是使用aboveskip和,belowskip其初始设置为\medskipamount

\begin{lstlisting}[aboveskip=-1.4\medskipamount]

代码:

\documentclass{article}

\tracingonline1
\tracingoutput1
\tracingparagraphs1
\usepackage{lua-visual-debug}
\usepackage{listings}
\usepackage{unravel}
\makeatletter
% \def\rst{\gdef\everypar={\setbox \z@ \lastbox }}
% \def\rst{\gdef\everypar##1{##1\unvbox}}
\def\rst{\leavevmode\unskip \lastbox\hfill} % \unvbox \z@ \lastbox \leavevmode \unhbox\z@
\makeatother

\begin{document}

Test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test ...

\begin{minipage}[t]{1em}
A
% \rst% \unravel{\bgroup
\end{minipage}
\hfill
% \rst
\begin{minipage}[t]{\dimexpr\textwidth-2\parindent-2.2em}%
% }
%\vspace{-1.2\baselineskip}
\begin{lstlisting}[aboveskip=-1.4\medskipamount]
sslg kaha kshd kajshd
asl q7ey q[peo [pdv
sdfk a9su qpowie e
asj asy dqoi poai
\end{lstlisting}
\end{minipage}

Test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test ...

% http://tex.stackexchange.com/questions/36712/how-to-place-two-code-/36737
\begin{minipage}[t]{0.45\linewidth}
\begin{lstlisting}[caption={Some XML Caption}]
  .. xml code ...
  .. xml code ...
  .. xml code ...
  .. xml code ...
  .. xml code ...
  .. xml code ...
\end{lstlisting}
% \unravel{\bgroup
\end{minipage}
%
\begin{minipage}[t]{0.45\linewidth}
% }
\begin{lstlisting}[caption={Some Javascript Caption}]
  ... javascript code ...
  ... javascript code ...
  ... javascript code ...
\end{lstlisting}
\end{minipage}

\end{document}

在此处输入图片描述

答案2

\vspace{-1.2\baselineskip}好吧,我找到了一个手动解决方法,即在第二次启动后立即使用{minipage};然后输出如下:

测试02c.png

... 我猜,这就是[t]+[t]所期望做的。

我使用该unravel包逐步遍历关键部分,并在 meld 中比较这些日志;问题似乎减少为\everypar两次运行的不同(参见下面的评论) - 所以我尝试了一些弹出的命令(\unvskip\lastbox- 所有我不理解的命令并且找不到快速参考),但我无法控制它们 - 所以最后我只是在那里添加了一个 \vspace,它似乎起作用了(我之前也尝试过 \vspace,但是由于我把它放在其他地方所以它不起作用)。

无论如何,代码是:

\documentclass{article}

\tracingonline1
\tracingoutput1
\tracingparagraphs1
\usepackage{lua-visual-debug}
\usepackage{listings}
\usepackage{unravel}
\makeatletter
% \def\rst{\gdef\everypar={\setbox \z@ \lastbox }}
% \def\rst{\gdef\everypar##1{##1\unvbox}}
\def\rst{\leavevmode\unskip \lastbox\hfill} % \unvbox \z@ \lastbox \leavevmode \unhbox\z@
\makeatother

\begin{document}

Test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test ...

\begin{minipage}[t]{1em}
A
% \rst% \unravel{\bgroup
\end{minipage}
\hfill
% \rst
\begin{minipage}[t]{\dimexpr\textwidth-2\parindent-2.2em}%
% }
\vspace{-1.2\baselineskip}
\begin{lstlisting}
sslg kaha kshd kajshd
asl q7ey q[peo [pdv
sdfk a9su qpowie e
asj asy dqoi poai
\end{lstlisting}
\end{minipage}

Test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test sentence test ...

% http://tex.stackexchange.com/questions/36712/how-to-place-two-code-/36737
\begin{minipage}[t]{0.45\linewidth}
\begin{lstlisting}[caption={Some XML Caption}]
  .. xml code ...
  .. xml code ...
  .. xml code ...
  .. xml code ...
  .. xml code ...
  .. xml code ...
\end{lstlisting}
% \unravel{\bgroup
\end{minipage}
%
\begin{minipage}[t]{0.45\linewidth}
% }
\begin{lstlisting}[caption={Some Javascript Caption}]
  ... javascript code ...
  ... javascript code ...
  ... javascript code ...
\end{lstlisting}
\end{minipage}

\end{document}

% diff via unravel 1:
% <| {\par }{}\begingroup \setbox 12=\vbox {\par }\vtop {}\@end@tempboxa
% <| \endgroup  \begingroup \setbox 12=\vbox { ok

% <| {\par }\begingroup \setbox 12=\vbox {\par }\vtop {}\@end@tempboxa
% <| \endgroup  \begingroup \setbox 12=\vbox { nok

% diff via unravel 2 - from:
% <| {\par }
% ||
% |> \unhbox \voidb@x

% to:
% [===== Step 24 =====] \unhbox = \unhbox : \everypar={}
% <| {\par }
% ||
% |> \unhbox \voidb@x \@pboxswfalse \setlength \@tempdima

% [===== Step 37 =====] \unhbox = \unhbox : \everypar={{\setbox \z@ \la...
% <| {\par }
% ||
% |> {\setbox \z@ \lastbox }\everypar {}\@endpefalse \unhbox \voidb@x

相关内容