TikZ 矩阵中文本和箭头的位置

TikZ 矩阵中文本和箭头的位置

我想在 TikZ 中放置文本matrix,但它总是从底部开始!所以,我的问题是如何强制它从顶部开始?

我的 MWE:

\documentclass{article}    
\usepackage[svgnames]{xcolor}
\usepackage{tikz}

        \usetikzlibrary{
                arrows, chains, matrix, 
                positioning, 
                shadows,
                shapes, shapes.callouts,graphs, calc,
                shapes.geometric,
                shapes.misc,
                intersections,
               matrix, % to draw a table
              fit                  
                }

 %\newcommand{\vlab}[2]{%
        %           \tikz[baseline,inner sep=0] \node[anchor=base] (#1){#2};
            %       }

\begin{document}


 \begin{tikzpicture}[every node/.style={anchor=base,text depth=.5ex},baseline]
  \matrix %[draw=red]
   {
     \node[text height=2ex,fill=Orange!30,text width=6cm] {Local case}; & \node[text height=2ex,fill=Green!30,text width=7cm]{Global case}; \\
     \node[text height=6cm,fill=Yellow!30,align=left,text width=6cm] (noda) {
        \begin{itemize}
           \item We have \[\left[\bar \theta\right]=\left[\bar\partial (h^{-1}\partial h)\right]=c_1(\mathcal L)\,
                  =\left[K\right]\]  \\
           \item Since  $h=\exp(\mathcal K)$ we have:
                \[
                    \theta = \exp(-\mathcal K)\partial (\exp(\mathcal K))= \tikz[baseline,inner sep=0] 
                    \node[anchor=base](Kpot){$\partial\mathcal K$};
                    \tikz[baseline,inner sep=0] \node[below= of Kpot](Kpot2){\scriptsize So a K\"ahler transf. corresponds to a gauge 
                          transformation };
                     \tikz[overlay]\draw[->,red] (Kpot) to (Kpot2);
                \]
        \end{itemize}        
          }; 
     & \node[fill=Cyan!30,text height=6cm,,text width=7cm] {
      \begin{itemize}
        \item $\mathcal L$ is a flat bundle i.e $h=cst$\\
        \item Since $\theta \sim \partial h$, we can choose a vanishing connection:
            \[
                \theta=\bar \theta=0
             \]
      \end{itemize}       
               };\\
        %\node[fill=Purple] {a}; & \node[fill=LightBlue] {X}; & \node[fill=Aquamarine] {g}; \\
    };
\end{tikzpicture}

答案1

关于你的例子,存在一些问题:

  • A\matrix已经创建了节点,因此我认为嵌套节点是不可取的。
  • \item当在 内部时,需要将每个括在花括号内\matrix,例如:\item{<content goes here>}
  • 要为单元格着色,请使用|[fill=<color>]|

输出

在此处输入图片描述

代码

\documentclass{article}    
\usepackage[svgnames]{xcolor}
\usepackage[margin=2cm]{geometry}
\usepackage{tikz}
\usepackage{amsmath,amssymb}

\usetikzlibrary{
    arrows, chains, matrix, 
    positioning, 
    shadows,
    shapes, shapes.callouts,
    graphs, calc,
    shapes.geometric,
    shapes.misc,
    intersections,
    matrix,fit,           
}

\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture, anchor=base west] \node[text depth=, text width=] (#1) {#2};}

\begin{document}
\begin{tikzpicture}
\matrix [
matrix of nodes,
nodes in empty cells,
every node/.style={align=left},
row 1/.style={text width=.45\linewidth,text depth=2ex},
row 2/.style={nodes={font=\footnotesize, text width=.45\linewidth,text depth=6cm}}
] 
{
|[fill=Orange!30]| Local Case & |[fill=Green!30]| Global case \\
|[fill=Yellow!30]|
\begin{itemize}
   \item{We have \[\left[\bar \theta\right]=\left[\bar\partial (h^{-1}\partial h)\right]=c_1(\mathcal L)\,
            =\left[K\right]\]}
   \item{Since  $h=\exp(\mathcal K)$ we have:
        \[\theta = \exp(-\mathcal K)\partial (\exp(\mathcal K))\,
            =\tikzmark{Kpot}{$\partial\mathcal K$}\]}            
\end{itemize}
\tikzmark{Kpot2}{\scriptsize So a K\"ahler transf. corresponds to a gauge transformation}
& 
|[fill=Cyan!30]|
\begin{itemize}
    \item{$\mathcal L$ is a flat bundle i.e $h=cst$}
    \item{Since $\theta \sim \partial h$, we can choose a vanishing connection:
        \[
            \theta=\bar \theta=0
        \]}
\end{itemize}\\
};
\end{tikzpicture}
\tikz[overlay, remember picture]{%
    \draw[->,red] (Kpot.south) -- (Kpot2.north);
}
\end{document}

答案2

TiKZ-matrix您更喜欢使用而不是。文本在 中比在 中tcolorboxes更容易复合。使用 ,您的框可以像矩阵一样分布。当然,与它们兼容。tcolorboxnodetcbrastertikzmark

\documentclass{article}    
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[svgnames]{xcolor}
\usepackage[margin=2cm]{geometry}
\usepackage{tikz}
\usepackage{amsmath,amssymb}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\usetikzlibrary{tikzmark}

\begin{document}
\lipsum[1]

\begin{tcbitemize}[raster columns=2, 
    raster column skip=0pt, 
    raster row skip=0pt,
    raster equal height=rows,
    arc=0mm,
    boxrule=0pt,
    coltitle=black,
    ]
\tcbitem[colbacktitle=Orange!30, colback=Yellow!20, adjusted title= Local Case]
\begin{itemize}
   \item We have \[\left[\bar \theta\right]=\left[\bar\partial (h^{-1}\partial h)\right]=c_1(\mathcal L)\,
            =\left[K\right]\] 
   \item Since  $h=\exp(\mathcal K)$ we have:
        \[\theta = \exp(-\mathcal K)\partial (\exp(\mathcal K))\,
            =\partial\mathcal K\tikzmark{Kpot}\]            
\end{itemize}
\tikzmark{Kpot2}So a Kähler transf. corresponds to a gauge transformation.
\begin{tikzpicture}[remember picture, overlay]
\draw[red, shorten >=1mm, shorten <=1mm, ->] ([yshift=1mm]pic cs:Kpot) -- ++(0:3mm) |- ([shift={(-3mm,5mm)}]pic cs:Kpot2)|-([shift={(0mm,1mm)}]pic cs:Kpot2);
\end{tikzpicture}
\tcbitem[colbacktitle=Green!30, colback=Cyan!30, adjusted title=Global Case]
\begin{itemize}
    \item $\mathcal L$ is a flat bundle i.e $h=cst$
    \item Since $\theta \sim \partial h$, we can choose a vanishing connection:
        \[
            \theta=\bar \theta=0
        \]
\end{itemize}
\tcbitem[colbacktitle=Red!30, colback=Orange!40, adjusted title= Local Case]
\begin{itemize}
   \item We have \[\left[\bar \theta\right]=\left[\bar\partial (h^{-1}\partial h)\right]=c_1(\mathcal L)\,
            =\left[K\right]\] 
   \item Since  $h=\exp(\mathcal K)$ we have:
        \[\theta = \exp(-\mathcal K)\partial (\exp(\mathcal K))\,
            =\partial\mathcal K\]            
\end{itemize}
So a Kähler transf. corresponds to a gauge transformation.
\begin{tikzpicture}[remember picture, overlay]
\draw[red, shorten >=1mm, shorten <=1mm, ->] ([yshift=1mm]pic cs:Kpot) -- ++(0:3mm) |- ([shift={(-3mm,5mm)}]pic cs:Kpot2)|-([shift={(0mm,1mm)}]pic cs:Kpot2);
\end{tikzpicture}
\tcbitem[colbacktitle=Purple!30, colback=Blue!30, adjusted title=Global Case]
\begin{itemize}
    \item $\mathcal L$ is a flat bundle i.e $h=cst$
    \item Since $\theta \sim \partial h$, we can choose a vanishing connection:
        \[
            \theta=\bar \theta=0
        \]
\end{itemize}
\end{tcbitemize}
\end{document}

在此处输入图片描述

更新:

将其视为一个长评论,而不是答案。OP 评论关于使用matrix多行彩色表格,例如这个我认为这只是一个彩色的表格,并且colortbl可以用于以下用途:

\documentclass{article}

\usepackage[table,svgnames]{xcolor}
%\usepackage{colortbl}
\usepackage{amsmath,amssymb}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

\def\arraystretch{2}
\setlength\arrayrulewidth{0.6pt} % see http://tex.stackexchange.com/a/53935/1952
\begin{tabular}{l|l}
\rowcolor{Orange!30}Local Case & Global Case \\ \hline
\rowcolor{Red!30}\ \textbullet\ \# $\text{vector multiplets}\equiv n = \dim \mathcal{M}$ 
&
\ \textbullet\ \# $\text{vector multiplets}\equiv n = \dim \mathcal{M}$ 
\\\hline
\rowcolor{Cyan!30}\ \textbullet\ \# $\text{vector fields}\equiv \overline{n} = n$ 
&
\ \textbullet\ \# $\text{vector fields}\equiv \overline{n} = n + \textcolor{red}{1}\tikzmark{a}$\tikz[remember picture, overlay]\draw[red] ([yshift=0.75ex]pic cs:a)--++(0.25,.25) node[right]{graviphoton}; 
\\\hline
\rowcolor{Blue!30}\ \textbullet\ \# $\text{Rank of SV} \equiv 2\overline{n} = 2n$ 
&
\ \textbullet\ \# $\text{Rank of SV} \equiv 2\overline{n} = 2n+2$ 
\\
\end{tabular}
\end{document}

在此处输入图片描述

相关内容