longtable 中奇怪的對齊問題

longtable 中奇怪的對齊問題

我編寫了一些用於格式化用例的環境。由於某種原因,我的longtable.我認為那裡有一些看不見的佔位符把一切搞亂了,但幾個小時後,刪除所有不必要的空格後,我找不到它。

這是我的環境:

\newenvironment{ucflowofevents}{%
\newcommand{\event}[1]{\item{##1}}%
\begin{enumerate}
}{%
\end{enumerate}
}

\newenvironment{ucentryconditions}{%
\newcommand{\cond}[1]{\item{##1}}%
\begin{itemize}
}{%
\end{itemize}
}

\newenvironment{ucexitconditions}{%
\newcommand{\cond}[1]{\item{##1}}%
\begin{itemize}
}{%
\end{itemize}
}

\newenvironment{ucrequirements}{%
\newcommand{\req}[1]{\item{##1}}%
\begin{itemize}
}{%
\end{itemize}
}

\newenvironment{pcusecase}[1]{%
    \newcommand{\row}[3][\hline]{##2 & ##3 \\ ##1}
    \newcolumntype{L}{>{\vspace{-1.0\baselineskip}\flushleft\arraybackslash}p{4cm}}%
    \newcolumntype{R}{>{\vspace{-1.0\baselineskip}\raggedright\arraybackslash}b{10cm}}%
    \newcommand{\giveninitactors}{REQUIRED!!!}%
    \newcommand{\givenevents}{REQUIRED!!!}%
    \newcommand{\givencommswith}{}%
    \newcommand{\givenentries}{}%
    \newcommand{\givenexits}{}%
    \newcommand{\givenreqs}{}%
    \newcommand{\initactors}[1]{\gdef\giveninitactors{##1}}%
    \newcommand{\commswith}[1]{\gdef\givencommswith{##1}}%
    \newcommand{\events}[1]{\gdef\givenevents{\begin{ucflowofevents}##1\end{ucflowofevents}}}%
    \newcommand{\entries}[1]{\gdef\givenentries{\begin{ucentryconditions}##1\end{ucentryconditions}}}%
    \newcommand{\exits}[1]{\gdef\givenexits{\begin{ucexitconditions}##1\end{ucexitconditions}}}%
    \newcommand{\reqs}[1]{\gdef\givenreqs{\begin{ucrequirements}##1\end{ucrequirements}}}%
    \let\givencommswith\empty%
    \let\givenentries\empty%
    \let\givenexits\empty%
    \let\givenreqs\empty%
    \centering%
    \begin{longtable}{|LR|}\hline %
        \row{Use Case:}{#1}
}{%
        \row{Initiating Actors:}{\giveninitactors}%
        \ifx\givencommswith\empty\else \row[]{Communicates With:}{\givencommswith} \fi %\hline %
        \hline\row{Flow of Events:}{\givenevents} %
        \ifx\empty\givenentries\else \row{Entry Conditions:}{\givenentries} \fi %
        \ifx\empty\givenexits\else \row{Exit Conditions:}{\givenexits} \fi %
        \ifx\empty\givenreqs\else \row{Quality Requirements:}{\givenreqs} \fi%
    \end{longtable}%
}

前四個只是設定了事件流程、進入和退出條件以及品質要求的清單。但pcusecase設定了longtable.

注意\newcolumntype定義:

    \newcolumntype{L}{>{\vspace{-1.0\baselineskip}\flushleft\arraybackslash}p{4cm}}%
    \newcolumntype{R}{>{\vspace{-1.0\baselineskip}\raggedright\arraybackslash}b{10cm}}%

我真正想要的是它們都頂部對齊,但我指定了b右側 (R) 列,因為它誇大了發生的情況。這是我的用例:

\begin{pcusecase}{TestUseCase}%
    \initactors{Rider, Admin}%
    \commswith{GPSService}%
    \events{\item{Event 1}%
                    \item{Event 2}}%
    \entries{\cond{Entry Condition 1}%
                     \cond{Entry Condition 2}}%
    \exits{\cond{Exit Condition 1}%
                 \cond{Exit Condition 1}}%
    \reqs{\req{Requirement 1}%
                \req{Requirement 2}
                \req{Requirement 3}}%
\end{pcusecase}

這給出了這個輸出:

左上對齊?右下對齊?

請注意,對於前三行,右側單元格按照應有的方式底部對齊,但對於其餘行,左側單元格底部對齊,右側單元格頂部對齊。

如果我指定左應該下對齊,右上對齊

    \newcolumntype{L}{>{\vspace{-1.0\baselineskip}\flushleft\arraybackslash}b{4cm}}%
    \newcolumntype{R}{>{\vspace{-1.0\baselineskip}\raggedright\arraybackslash}p{10cm}}%

我明白了:

左上對齊?右下對齊?

某種程度上,左側是頂部對齊,右側是底部對齊。最奇怪的一個,也可能是會提示某人的一個,是當我指定兩者都應該底部對齊並得到這個時:

搞什麼?

在所有三個版本中,左上角三個單元格的對齊方式沒有改變。我已經盯著看好幾個小時了我需要一些新的眼光來看待這個問題。非常感謝您的幫忙...

答案1

以下示範了標準垂直對齊選項的工作原理:

\documentclass{article}
\usepackage{tikz}
\begin{document}
  \newcommand\demobox[1]{%
  \fbox{%
    \begin{minipage}[#1]{.25\textwidth}
      \tikz[baseline=(n.base)]{%
        \node (n) [inner sep=0pt, outer sep=0pt, text width=\linewidth] {Top};
        \draw [red] (n.west |- n.base) -- (n.east |- n.base);}
      \par
      This is a box with some content which should be longer than can be accommodated on one line.
      \par
      \tikz[baseline=(n.base)]{%
        \node (n) [inner sep=0pt, outer sep=0pt, anchor=base, text width=\linewidth] {Bottom};
        \draw [red] (n.west |- n.base) -- (n.east |- n.base);}
    \end{minipage}}}
\demobox{t}
\demobox{b}
\demobox{c}
\end{document}

對齊

紅線標記每個 的第一行和最後一行的基線minipage。因為第一個與 對齊t,第二個與 對齊b,所以第一條第一行的基線和第二條最後一行的基線對齊。 (c只是為了比較。)

如果與常規文字行的基線對齊,也會發生同樣的情況:

This is a line of regular text across the page. Here we go\dots\par
and some text \demobox{t}
and some more \demobox{b}\par

與文字對齊

另一個複雜之處是enumerate,預設情況下,環境在第一個項目之前和最後一個項目之後包含垂直間距:

\documentclass{article}
\begin{document}
  \fbox{%
    \parbox[t]{.25\textwidth}{%
      \begin{enumerate}
        \item Item
        \item Item
        \item Item
      \end{enumerate}}} and here is the line of text.
  \fbox{%
    \parbox[t]{.25\textwidth}{%
      Top line of text.\par Next line.\par Bottom line.}}

  \fbox{%
    \parbox[b]{.25\textwidth}{%
      \begin{enumerate}
        \item Item
        \item Item
        \item Item
      \end{enumerate}}} and here is the line of text.
  \fbox{%
    \parbox[b]{.25\textwidth}{%
      Top line of text.\par Next line.\par Bottom line.}}
\end{document}

枚舉對齊

相關內容