3

Based on one of the example posted How to create new table environment, I modified to my needs,

\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}

enter image description here

David Carlisle
  • 757,742
Raama
  • 1,465
  • 1
    Without a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages it is difficult to know. But you could try adding text width=<length> options to the nodes. – Peter Grill Apr 04 '12 at 15:39
  • I modified that code with what I tried. – Raama Apr 04 '12 at 15:44

2 Answers2

2

I modified your code to show the problem (with text in red) and it produces:

enter image description here

After adding text width=1.5cm:

enter image description here

And changing \newcommand{\nl}{\newline} to \newcommand{\nl}{\\}:

enter image description here

Code:

\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}

Peter Grill
  • 223,288
1

Change the \nl to \\ in the \tabnode and it works fine.

\tabnode{test \\ text1 \\ text2}
Torbjørn T.
  • 206,688