文字和節點內第一項之間的垂直間距不一致

文字和節點內第一項之間的垂直間距不一致

附加的程式碼產生以下幻燈片。

在此輸入影像描述

儘管四個矩形節點的程式碼彼此相等,但矩形內文字和第一個項目之間的垂直間距小於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}

在此輸入影像描述

相關內容