
텍스트가 있는 긴 테이블 셀에서 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)
0으로 나누게 됩니다. 중앙으로 설정해도 텍스트 중앙에 표시되지 않는 것 같습니다.
원하는 출력은 text와 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}