3

I have this table, where the first column has inline tikz nodes. I would like the text of the nodes to be vertically aligned with the text of the table.

I found this question about his (among others), the problem is that I can't use baseline=(v1.base) to aline v1, because v1 does not know itself before being shown.

(I'm using pgfplotstable, but I don't think that changes anything)

MWE:

\documentclass[10pt,a4paper,twoside]{report}

\usepackage{geometry}   
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
\usepackage{setspace}
\setstretch{1.5}
\usepackage[table,pdftex]{xcolor} 
%---------------------------------- tikz ---------------------------------------
\usepackage{tikz}
\usetikzlibrary{positioning,chains,fit,shapes,calc,arrows,patterns,external,shapes.callouts,graphs}
\tikzstyle{fancy}=[rectangle,rounded corners=1mm,thick,draw=white,ultra thin,
                   top color=white,bottom color=black!20,%
                   minimum height=.5cm,minimum width=.5cm,inner sep=2pt]


\usepackage{pgfplots}          % to print charts
\pgfplotsset{compat=1.9}

\usepackage{pgfplotstable}
\usepackage{booktabs,colortbl}
\usepackage{fixltx2e} 

\begin{document}

\begin{table}
  \centering
  \caption{Parameters in blue.}
  \label{tab:1024groups1}
  \vspace{1em}

  \pgfplotstabletypeset[
  col sep=comma,
    columns/groups/.style={
        string type,
        column name=g.,},
    columns/vmin/.style={
%       string type,
        column name=$n)$,},
    columns/vmax/.style={
        column name=$(n$,},
    columns/density/.style={
        column name=$d$,},
    every head row/.style={
        after row=\midrule},
  every even row/.style={
    before row={\rowcolor{cyan!7}}},
  ]{
        groups,vmin,vmax,density
        \tikz[baseline=0] {\node[fancy] at (0,0) (v1){1};},2,1,1
        \tikz[baseline=0] {\node[fancy] at (0,0)(v2){2};},10,100,0
        \tikz[baseline=0] {\node[fancy] at (0,0)(v3){3};},10,25,0
        \tikz[baseline=0] {\node[fancy] at (0,0)(v4){4};},2,70000,0
        \tikz[baseline=0] {\node[fancy] at (0,0) (v1){1};},2,10,1
        \tikz[baseline=0] {\node[fancy] at (0,0)(v2){2};},100,10,0
        \tikz[baseline=0] {\node[fancy] at (0,0)(v3){3};},10,25,0
        \tikz[baseline=0] {\node[fancy] at (0,0)(v4){4};},200,7,0
      }

  \vspace{1em}

\end{table}
\end{document}

enter image description here

3

Anchor them to the base:

\documentclass[10pt,a4paper,twoside]{report}

\usepackage{geometry}   
    \geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
\usepackage{setspace}
\setstretch{1.5}
\usepackage[table,pdftex]{xcolor} 
%---------------------------------- tikz ---------------------------------------
\usepackage{tikz}
\usetikzlibrary{positioning,chains,fit,shapes,calc,arrows,patterns,external,shapes.callouts,graphs}
\tikzstyle{fancy}=[rectangle,rounded corners=1mm,thick,draw=white,ultra thin,
                   top color=white,bottom color=black!20,%
                   minimum height=.5cm,minimum width=.5cm,inner sep=2pt]


\usepackage{pgfplots}          % to print charts
\pgfplotsset{compat=1.9}

\usepackage{pgfplotstable}
\usepackage{booktabs,colortbl}
\usepackage{fixltx2e} 

\begin{document}

\begin{table}
  \centering
  \caption{Parameters in blue.}
  \label{tab:1024groups1}
  \vspace{1em}

  \pgfplotstabletypeset[
  col sep=comma,
    columns/groups/.style={
        string type,
        column name=g.,},
    columns/vmin/.style={
%       string type,
        column name=$n)$,},
    columns/vmax/.style={
        column name=$(n$,},
    columns/density/.style={
        column name=$d$,},
    every head row/.style={
        after row=\midrule},
  every even row/.style={
    before row={\rowcolor{cyan!7}}},
  ]{
        groups,vmin,vmax,density
        \tikz[baseline=0] {\node[fancy,anchor=base] at (0,0) (v1){1};},2,1,1
        \tikz[baseline=0] {\node[fancy,anchor=base] at (0,0)(v2){2};},10,100,0
        \tikz[baseline=0] {\node[fancy,anchor=base] at (0,0)(v3){3};},10,25,0
        \tikz[baseline=0] {\node[fancy,anchor=base] at (0,0)(v4){4};},2,70000,0
        \tikz[baseline=0] {\node[fancy,anchor=base] at (0,0) (v1){1};},2,10,1
        \tikz[baseline=0] {\node[fancy,anchor=base] at (0,0)(v2){2};},100,10,0
        \tikz[baseline=0] {\node[fancy,anchor=base] at (0,0)(v3){3};},10,25,0
        \tikz[baseline=0] {\node[fancy,anchor=base] at (0,0)(v4){4};},200,7,0
      }

  \vspace{1em}

\end{table}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.