节点居中,而不是右对齐

节点居中,而不是右对齐

为什么这三个节点位于中央而不是右侧?

在此处输入图片描述

\documentclass{article}
\usepackage{tikz,fourier}

\begin{document}
\xdef\LW{.99*241pt}%\linewidth
\xdef\BLS{\baselineskip} 

\begin{tikzpicture}[y={(0,-\BLS)},inner sep=0pt,outer sep=0pt]

\node[draw,minimum width=1.2,minimum height=2.5*\BLS,text width=1cm,align=flush center,font=\scriptsize] (11) at (0,0) {Poids jusqu'\`a} ; 

\node[draw,anchor=north west,minimum width=(\LW-1.2cm),minimum height=\BLS,] at (11.north east) {Tarifs nets (\$)};

\node[draw,anchor=south west,minimum width=(\LW-1.2cm)*.24,minimum height=1.5*\BLS,align=flush center,font=\scriptsize,text width=1.6cm] (22) at (11.south east) {Vers France m\'etropolitaine};

\node[draw,anchor=south west,minimum width=(\LW-1.2cm)*.38,minimum height=1.5*\BLS,align=flush center,font=\scriptsize,text width=1.8cm] (23) at (22.south east) {Vers zone outre-mer 1};

\node[draw,anchor=south west,minimum width=(\LW-1.2cm)*.38,minimum height=1.5*\BLS,align=flush center,font=\scriptsize,text width=1.8cm] at (23.south east) {Vers zone outre-mer 2};

\foreach \t [count=\i from 2,evaluate=\i as \j using int(\i+1)] in {%
{0,56}\,\$,
{0,90}\,\$,
{6,04}\,\$} {%
\node[draw,anchor=north east,align=flush right, minimum height=\BLS,minimum width=(\LW-1.2cm)*.24] (\j2) at (\i2.south east) {\t};
}
\end{tikzpicture}
\end{document}

答案1

要对齐,您需要一个具有给定宽度的框。为此,您必须提供 text width。如果您愿意,也可以提供 minimum width

\node[draw,anchor=north east,align=flush right, minimum height=\BLS,text width=(\LW-1.2cm)*.24] (\j2) at (\i2.south east) {\t};

完整代码:

\documentclass{article}
\usepackage{tikz,fourier}

\begin{document}
\xdef\LW{.99*241pt}%\linewidth
\xdef\BLS{\baselineskip}

\begin{tikzpicture}[y={(0,-\BLS)},inner sep=0pt,outer sep=0pt]

\node[draw,minimum width=1.2,minimum height=2.5*\BLS,text width=1cm,align=flush center,font=\scriptsize] (11) at (0,0) {Poids jusqu'\`a} ;

\node[draw,anchor=north west,minimum width=(\LW-1.2cm),minimum height=\BLS,] at (11.north east) {Tarifs nets (\$)};

\node[draw,anchor=south west,minimum width=(\LW-1.2cm)*.24,minimum height=1.5*\BLS,align=flush center,font=\scriptsize,text width=1.6cm] (22) at (11.south east) {Vers France m\'etropolitaine};

\node[draw,anchor=south west,minimum width=(\LW-1.2cm)*.38,minimum height=1.5*\BLS,align=flush center,font=\scriptsize,text width=1.8cm] (23) at (22.south east) {Vers zone outre-mer 1};

\node[draw,anchor=south west,minimum width=(\LW-1.2cm)*.38,minimum height=1.5*\BLS,align=flush center,font=\scriptsize,text width=1.8cm] at (23.south east) {Vers zone outre-mer 2};

\foreach \t [count=\i from 2,evaluate=\i as \j using int(\i+1)] in {%
{0,56}\,\$,
{0,90}\,\$,
{6,04}\,\$} {%
\node[draw,anchor=north east,align=flush right, minimum height=\BLS,text width=(\LW-1.2cm)*.24] (\j2) at (\i2.south east) {\t};
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容