在 tikz 节点中使用 itemize 等环境会改变垂直对齐方式

Using an environment such as itemize in a tikz node shifts vertical alignment

如果我在 tikz 节点中使用环境,垂直对齐方式会发生偏移。下面举例说明区别,第一种情况,没有使用环境,一切正常。

\begin{frame}

% alignment is correct without using itemize
\begin{tikzpicture}
\node[text width=\textwidth, text centered,fill=yellow, fill opacity=0.4,text opacity=1, rounded corners, inner sep= 0em, outer sep=0em]{test};
\end{tikzpicture}

% alignment is shifted vertically
\begin{tikzpicture}
\node[text width=\textwidth, text centered,fill=yellow, fill opacity=0.4,text opacity=1, rounded corners, inner sep= 0em, outer sep=0em]{\begin{itemize}
\item test
\end{itemize}};
\end{tikzpicture}

\end{frame}

您可以像这样解决问题:

\documentclass{beamer}

\usepackage{tikz}

\begin{document}
    
\begin{frame}

% alignment is correct without using itemize
\begin{tikzpicture}
\node[text width=\textwidth, text centered,fill=red, fill opacity=0.4,text opacity=1, rounded corners, inner sep= 0em, outer sep=0em]{test};
\end{tikzpicture}

\bigskip

% alignment is shifted vertically
\begin{tikzpicture}[baseline]
\node[text width=\textwidth, text centered,fill=red, fill opacity=0.4,text opacity=1, rounded corners, inner sep= 0em, outer sep=0em]{\begin{minipage}{\textwidth}\begin{itemize}
\item test
\end{itemize}\end{minipage}};
\end{tikzpicture}

\end{frame}
 
\end{document}