![将内联 tikz 节点文本与当前行文本对齐(在表格中)](https://linux22.com/image/321012/%E5%B0%86%E5%86%85%E8%81%94%20tikz%20%E8%8A%82%E7%82%B9%E6%96%87%E6%9C%AC%E4%B8%8E%E5%BD%93%E5%89%8D%E8%A1%8C%E6%96%87%E6%9C%AC%E5%AF%B9%E9%BD%90%EF%BC%88%E5%9C%A8%E8%A1%A8%E6%A0%BC%E4%B8%AD%EF%BC%89.png)
我有这个表,其中第一列有内联 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}