ロングテーブルセル内の tkzpicture の垂直配置

ロングテーブルセル内の tkzpicture の垂直配置

tkzpicture を縦方向の中央または上端に揃えて、長い表のセルにテキストを配置するのに苦労しています。 どういうわけか、下のベースラインに揃えられます。

中央揃えではなく上揃えで画像を表示する画像

すべてを上部に揃えるようにしています。

以下に簡略化した例を示します。

\documentclass{report}

\usepackage{tikz}
\usepackage{longtable}

\begin{document}

% define a square with text
\def\sqs{2.6cm}
\newcommand{\square}[3]{\node[inner sep=5pt, outer sep=5pt, minimum height=\sqs,minimum width=\sqs,fill=#3,draw,label={[align=center]center:#2}] at (#1){};}

\newcommand{\someset}[4]{
    \begin{tikzpicture}[baseline=(current bounding box.center)]
        \square{0,3}{A}{#1};
        \square{3,3}{B}{#2};
        \square{0,0}{C}{#3};
        \square{3,0}{D}{#4};
    \end{tikzpicture}
}
% Smaller version to use in tables.
\newcommand{\smallset}[4]{\resizebox{2.3cm}{1cm}{\someset{#1}{#2}{#3}{#4}}}

\begin{longtable}[t]{|p{2cm}||p{3cm}|p{2cm}|}
\hline 
foo & \smallset{red}{green}{green}{red} & some long text that will be on many lines and so on some long text that will be on many lines and so on  \\
\hline
foo & \smallset{red}{green}{green}{red} & boo \\
\hline
\end{longtable}
\end{document}

baseline=(current bounding box.center)に設定するとbaseline=(current bounding box.north)、ゼロ除算が行われます。center に設定すると、テキストの中央に配置されないようです。

望ましい出力は、テキストと tkzpicture の両方がすべて上揃えになっていることです。

答え1

\somesetこれにより、 との両方のベースラインが正しく配置されます\smallset

\documentclass{report}

\usepackage{tikz}
\usepackage{longtable}

\begin{document}

% define a square with text
\def\sqs{2.6cm}
\newcommand{\square}[3]{\node[inner sep=5pt, outer sep=5pt, minimum height=\sqs,minimum width=\sqs,fill=#3,draw,label={[align=center]center:#2}] at (#1){};}

\newcommand{\someset}[4]{
    \begin{tikzpicture}[baseline=(BASE)]
        \square{0,3}{A}{#1};
        \square{3,3}{B}{#2};
        \square{0,0}{C}{#3};
        \square{3,0}{D}{#4};
      \path (current bounding box.north) ++(0pt,-\ht\strutbox) coordinate (BASE);
    \end{tikzpicture}
}
% Smaller version to use in tables.
\newcommand{\smallset}[4]{\raisebox{\dimexpr \ht\strutbox-\height}% set baseline
  {\resizebox{2.3cm}{2cm}%
    {\raisebox{\depth}% make height total height
      {\someset{#1}{#2}{#3}{#4}}}}}

\begin{longtable}{|p{2cm}||p{3cm}|p{2cm}|}
\hline 
foo & \smallset{red}{green}{green}{red} & some long text that will be on many lines and so on some long text that will be on many lines and so on  \\
\hline
foo & \smallset{red}{green}{green}{red} & boo \\
\hline
\end{longtable}
\end{document}

関連情報