TikZ – 如何创建节点

TikZ – 如何创建节点

根据发布的一个例子如何创建新的表环境,我根据自己的需要进行了修改,

\documentclass{article}
\makeatletter
\usepackage[labelformat=empty]{caption}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,shadows,arrows}
\usetikzlibrary{fit,shapes.geometric}
\newcounter{nodemarkers}
\newcommand\circletext[1]{%
    \tikz[overlay,remember picture] 
        \node (marker-\arabic{nodemarkers}-a) at (0,1.5ex) {};%
    #1%
    \tikz[overlay,remember picture]
        \node (marker-\arabic{nodemarkers}-b) at (0,0){};%
    \tikz[overlay,remember picture,inner sep=2pt]
        \node[draw,ellipse,fit=(marker-\arabic{nodemarkers}-a.center) (marker-\arabic{nodemarkers}-b.center)] {};%
    \stepcounter{nodemarkers}%
}
\newcommand{\nl}{\newline}

\newcounter{nodecount}
\newcommand\tabnode[1]{\addtocounter{nodecount}{1} \tikz \node (\arabic{nodecount}) {#1};}
\tikzstyle{every picture}+=[remember picture,baseline]
\tikzstyle{every node}+=[inner sep=0pt,anchor=base,
minimum width=1cm,align=center,text depth=0.5ex,outer sep=1pt]
\tikzstyle{every path}+=[thick, rounded corners]

\begin{document}
\def\starttable#1{%
  \renewcommand{\arraystretch}{1.1}%
  \minipage{0.45\textwidth}
      \captionof{table}{#1}
      \tabular{p{1cm}p{1cm}p{1cm}p{1cm}}
} 
\def\stoptable{%
\endtabular
   \endminipage\hspace{30pt}}
\def\R #1|#2|#3|#4{ #1&#2&#3&#4}

\newpage
\begin{table}[h]
\centering
\starttable{}
 \R test \nl text1 \nl text2|test|test|test\\
 \R test|test|test|test\\
 \R test|test|test|test\\
\stoptable
%
\starttable{}
 \R \tabnode{test \nl text3 \nl text4}|test|test|test\\
 \R test|test|test|test\\
 \R test|test|test|test\\
\stoptable
\end{table}

\begin{tikzpicture}[overlay]
\draw [red] (1.west) -- (1.north west) -- (1.north east) -- (1.south east) -- (1.south west) -- cycle;
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

我修改了你的代码来显示问题(用红色文字),它产生了:

在此处输入图片描述

添加后text width=1.5cm

在此处输入图片描述

并更改\newcommand{\nl}{\newline}\newcommand{\nl}{\\}

在此处输入图片描述

代码:

\documentclass{article}
\makeatletter
\usepackage[labelformat=empty]{caption}
\usepackage{tikz}

\newcommand{\nl}{\\}

\newcounter{nodecount}
\newcommand\tabnode[1]{\addtocounter{nodecount}{1} \tikz \node [red] (\arabic{nodecount}) {#1};}
\tikzstyle{every picture}+=[remember picture,baseline]
\tikzstyle{every node}+=[inner sep=0pt,anchor=base,
minimum width=1cm,align=center,text depth=0.5ex,outer sep=1pt, text width=1.5cm]
\tikzstyle{every path}+=[thick, rounded corners]

\begin{document}
\def\starttable#1{%
  \renewcommand{\arraystretch}{1.1}%
  \minipage{0.45\textwidth}
      \captionof{table}{#1}
      \tabular{p{1cm}p{1cm}p{1cm}p{1cm}}
} 
\def\stoptable{%
\endtabular
   \endminipage\hspace{30pt}}
\def\R #1|#2|#3|#4{ #1&#2&#3&#4}

\newpage
\begin{table}[h]
\centering
\starttable{}
 \R \tabnode{test \nl text1 \nl text2}|test|test|test\\
% \R test|test|test|test\\
% \R test|test|test|test\\
\stoptable
%
%\starttable{}
% \R test \nl text3 \nl text4|test|test|test\\
% \R test|test|test|test\\
% \R test|test|test|test\\
%\stoptable
\end{table}

%\begin{tikzpicture}[overlay]
%\draw [green] (1.west) -- (1.north west) -- (1.north east) -- (1.south east) -- (1.south west) -- cycle;
%\end{tikzpicture}
\end{document}

答案2

将 更改\nl\\并且\tabnode它运行良好。

\tabnode{test \\ text1 \\ text2}

相关内容