我有这个表,其中第一列有内联 tikz 节点。我希望节点的文本与表的文本垂直对齐。
我发现这个问题关于他的(以及其他人),问题是我不能用它baseline=(v1.base)
来对齐 v1,因为 v1 在显示之前并不知道自己。
(我正在使用 pgfplotstable,但我认为这不会改变任何东西)
梅威瑟:
\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}
答案1
将它们锚固到基座上:
\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}