文本和节点内第一个项目之间的垂直分隔不一致

文本和节点内第一个项目之间的垂直分隔不一致

附加的代码产生以下幻灯片。

在此处输入图片描述

虽然四个矩形节点的代码彼此相等,但矩形内文本和第一个项目之间的垂直间距Testbox 1比其他框小。在花了很多时间找出错误后,我疲惫的眼睛终于需要一些帮助了。


\documentclass[
    handout
]{beamer}
\usepackage{tikz}

\tikzset{
   X/.style={rounded corners=5pt, line width=0.75pt, 
             rectangle,text width=4.5cm, align=left, 
             minimum height=3cm,draw},
   T/.style={font=\small,text width=4.5cm,anchor=north west}
}

\newcommand\XBox[1]{%
   \node[X, 
         append after command={
            node[T] at (\tikzlastnode.north west) {%
               #1
            }
         }
   ] {}; 
}

\begin{document}

\begin{frame}{Test slide}
   \begin{center}
      \begin{tikzpicture}

         \matrix[column sep=0.5cm, row sep=0.5cm, ampersand replacement=\&]{%
            \uncover<2->{%
               \XBox{%
                  Testbox 1
                  \begin{itemize}
                     \item Test 1
                  \end{itemize}
               }
            }
            \& 
            \uncover<3->{%
               \XBox{%
                  Testbox 2
                  \begin{itemize}
                     \item Test 2
                  \end{itemize}
               }
            }
            \\
            \uncover<5->{%
               \XBox{%
                  Testbox 4
                  \begin{itemize}
                     \item Test 4
                  \end{itemize}
               }
            }
            \& 
            \uncover<4->{%
               \XBox{%
                  Testbox 3
                  \begin{itemize}
                     \item Test 3
                  \end{itemize}
               }
            }
            \\
         };
      \end{tikzpicture}
   \end{center}
\end{frame}

\end{document}

答案1

如有疑问,请使用\leavevmode:)

\documentclass[
    handout
]{beamer}
\usepackage{tikz}

\tikzset{
   X/.style={rounded corners=5pt, line width=0.75pt, 
             rectangle,text width=4.5cm, align=left, 
             minimum height=3cm,draw},
   T/.style={font=\small,text width=4.5cm,anchor=north west}
}

\newcommand\XBox[1]{%
   \node[X, 
         append after command={
            node[T] at (\tikzlastnode.north west) {%
               #1%
            }%
         }%
   ] {}; 
}

\begin{document}

\begin{frame}{Test slide}
   \begin{center}\leavevmode
      \begin{tikzpicture}

         \matrix[column sep=0.5cm, row sep=0.5cm, ampersand replacement=\&]{%
            \uncover<2->{%
               \XBox{%
                  Testbox 1%
                  \begin{itemize}
                     \item Test 1
                  \end{itemize}
               }
            }
            \& 
            \uncover<3->{%
               \XBox{%
                  Testbox 2
                  \begin{itemize}
                     \item Test 2
                  \end{itemize}
               }
            }
            \\
            \uncover<5->{%
               \XBox{%
                  Testbox 4
                  \begin{itemize}
                     \item Test 4
                  \end{itemize}
               }
            }
            \& 
            \uncover<4->{%
               \XBox{%
                  Testbox 3
                  \begin{itemize}
                     \item Test 3
                  \end{itemize}
               }
            }
            \\
         };
      \end{tikzpicture}
   \end{center}
\end{frame}

\end{document}

在此处输入图片描述

相关内容