矩阵单元内容的单词节点

矩阵单元内容的单词节点

我尝试绘制与矩阵行的某些部分相关的各种内容,但对于\node (a) {this}; is one row\\矩阵中的行,只有弯曲括号之间的部分会打印在输出 pdf 中。这是我尝试实现的一个示例最终结果,我在 Inkscape 中完成了此操作。

在此处输入图片描述

这是与绘图无关的 mwe:

\documentclass[a4paper]{article}
\usepackage[verbose,vmargin=30mm,hmargin=20mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{matrix,calc}

\tikzset{
  texttable/.style={row sep=-\pgflinewidth, column sep=-\pgflinewidth,
        nodes={anchor=center,outer sep=0pt,inner sep=3pt,
        text width=#1,text depth=.5ex,text height=10pt, font=\large}}}

\setlength{\parindent}{0pt}

\begin{document}
\begin{tikzpicture}

    \matrix at (0,0) [matrix of nodes, nodes in empty cells,
    matrix anchor=north west,
    texttable={6cm}, align=right,row 1/.style={align=left},row 2/.style={align=right}] (tb1)
    {
    ceci est une pomme\\
%    \node (a) {ceci}; est une pomme\\  %%this outputs only "ceci"
    this is an apple\\
    };
\end{tikzpicture}
\end{document}

答案1

您可以subnodestikzmark图书馆使用。

\documentclass[a4paper]{article}
\usepackage[verbose,vmargin=30mm,hmargin=20mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{matrix,calc, decorations.pathreplacing}

\tikzset{
  texttable/.style={row sep=-\pgflinewidth, column sep=-\pgflinewidth,
        nodes={anchor=center,outer sep=0pt,inner sep=3pt,
        text width=#1,text depth=.5ex,text height=10pt, font=\large}}}

\setlength{\parindent}{0pt}

\usetikzlibrary{tikzmark}

\begin{document}

\begin{tikzpicture}[remember picture, overlay]
    \matrix at (0,0) [matrix of nodes, nodes in empty cells,
    matrix anchor=north west,
    texttable={6cm}, align=right,row 1/.style={align=left},row 2/.style={align=right}] (tb1)
    {
    \subnode{ceci}{ceci} est une pomme\\
    \subnode{this}{this} is an apple\\
    };
    \node (approx) at (ceci|-this) {$\approx$};
    \draw[decorate,decoration={brace, mirror}] (ceci.south west)--(ceci.south east);
    \draw[decorate,decoration={brace, mirror}] (this.south west)--(this.south east);
    \draw (approx.south)--++(-90:3mm)-|([yshift=-2mm]this.south);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

太期待评论了...

与 @Ignasi 的回答有非常小的风格差异 (+1):

  • 图片元素的样式定义为tikzpicture
  • 改变矩阵宽度的更简单方法
  • 子节点下方的书法括号
  • \approx符号作为子节点之间的线的标签插入
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,
                decorations.pathreplacing,
                    calligraphy,% had to be after decorations.pathreplacing
                matrix,
                tikzmark}

\begin{document}
    \begin{tikzpicture}[remember picture,
BC/.style = {decorate,
             decoration={calligraphic brace, amplitude=4pt, raise=0pt},
             thick,
             pen colour=black}, 
 sn/.style = {inner xsep=0pt},
lbl/.style = {sn, pos=0.6, fill=white},
                        ] 
\matrix (m) [matrix of nodes,
             nodes in empty cells,
             nodes = {text width=60mm,
                      text depth=.5ex, text height=3ex, font=\large,
                      inner ysep=1pt, anchor=center},
             row 1/.style={align=left},
             row 2/.style={align=right},
            ]
{
\subnode[sn]{a}{ceci} est une pomme \\
\subnode[sn]{b}{this} is an apple   \\
};
\draw[BC]   (a.south east) -- (a.south west);
\draw[BC]   (b.south east) -- (b.south west);
\draw[shorten <=5pt,shorten >=5pt]
            (a) -- node[lbl] {$\approx$} ++ (0,-1.2) -| (b);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

附录:

考虑到 OP 的评论,我必须对我的 MWE 进行以下更改:

  • 子节点之间箭头上的标签定义lbl应更改为 lbl/.style = {pos=#1, fill=white},
  • 子节点之间的箭头应更改为
\draw[shorten <=5pt,shorten >=5pt]
            (a) -- ++ (0,-1.2) -| node[lbl=0.25] {$\approx$} (b);

经过这些更改后,给定 MWE 的编译产生:

在此处输入图片描述

相关内容