1

There is a whitespace in the bottom of cells in column "Results", but no whitespace in the top of cells in that column. Also cells in column "Criteria" are not vertically aligned.

Any ideas how to fix this?

Thanks in advance.

\documentclass[a4paper,fontsize=12pt]{article}

\usepackage{tikz}
\usetikzlibrary{matrix, positioning}

\tikzset{
    trafficlight:red/.style = {%
        matrix of nodes,
        ampersand replacement=\&,
        nodes in empty cells,
        rounded corners,
        draw = blue!70,
        fill = blue!30,
        nodes = {circle, minimum size=3mm, anchor=center, draw=black},
        column 1/.style={nodes={fill=red}},
        column 2/.style={nodes={fill=gray!30}},
        column 3/.style={nodes={fill=gray!30}},
        column sep=3mm,
    },
    trafficlight:green/.style = {%
    matrix of nodes,
    ampersand replacement=\&,
    nodes in empty cells,
    rounded corners,
    draw = blue!70,
    fill = blue!30,
    nodes = {circle, minimum size=3mm, anchor=center, draw=black},
    column 1/.style={nodes={fill=gray!30}},
    column 2/.style={nodes={fill=gray!30}},
    column 3/.style={nodes={fill=green}},
    column sep=3mm,
    },
    trafficlight:yellow/.style = {%
    matrix of nodes,
    ampersand replacement=\&,
    nodes in empty cells,
    rounded corners,
    draw = blue!70,
    fill = blue!30,
    nodes = {circle, minimum size=3mm, anchor=center, draw=black},
    column 1/.style={nodes={fill=gray!30}},
    column 2/.style={nodes={fill=yellow}},
    column 3/.style={nodes={fill=gray!30}},
    column sep=3mm,
    }
}

%%% Работа с таблицами
\usepackage{tabularx} % Дополнительная работа с таблицами
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\renewcommand\tabularxcolumn[1]{m{#1}}

\begin{document}
\begin{table}[h]
    \centering
    \begin{tabularx}{\textwidth}{ | c | Y | }
        \hline
        Results & Criteria \\
        \hline
        \begin{tikzpicture}
            \matrix[trafficlight:red]{\& \& \\};
        \end{tikzpicture} & Test \\
        \hline
        \begin{tikzpicture}
            \matrix[trafficlight:yellow]{\& \& \\};
        \end{tikzpicture} & Test \\
        \hline
        \begin{tikzpicture}
            \matrix[trafficlight:green]{\& \& \\};
        \end{tikzpicture} & Test \\
        \hline
    \end{tabularx}
\end{table}
\end{document}

Problem

3
  • Do you want to remove the space entirely? Then add [baseline=(current bounding box.center)] to your {tikzpicture} environments.
    – Alan Munn
    Commented Dec 2, 2023 at 19:13
  • Welcome to TeX.SE!
    – Mensch
    Commented Dec 2, 2023 at 19:13
  • @AlanMunn No, I want to make this space symmetric from top and bottom for all cells (inside cell) in both "Results" and "Criteria" columns. Your suggestion remove space in Results column but make this space shifted to top in Criteria column.
    – kissmemiau
    Commented Dec 2, 2023 at 19:43

1 Answer 1

2

See if the following suggestion gives what you after:

\documentclass[a4paper,12pt]{article}
\usepackage{lipsum}

\usepackage{tikz}
\usetikzlibrary{fit, 
                matrix}
\newcommand\Semafor[3]%
{
\begin{tikzpicture}[baseline=-1.5mm]
\matrix (m) [matrix of nodes,
             nodes = {circle, draw, fill=#1,
                      minimum size = 4mm, inner sep=0mm, anchor=center},
             column sep = 1.5mm,
             ampersand replacement=\&
             ]
{
|[#1]| \&  |[#2]|    \&  |[#3]|  \\
};
\node[draw, rounded corners, inner sep=1mm, fit=(m)] {};
 \end{tikzpicture}%
}
\usepackage{ragged2e}
\usepackage{tabularray}

\begin{document}
\begin{table}[ht]
    \centering
    \begin{tblr}{hlines, vlines,
                 colspec = {Q[c] X[m, cmd={\RaggedRight}]},
                 row{1}  = {cmd={\Centering}},
                 row{2-Z}= {rowsep = 5pt}
                 }
Results                         &   Criteria    \\
\Semafor{red}{gray}{gray}       &   \lipsum[66] \\
\Semafor{gray}{yellow}{gray}    &   Test        \\
\Semafor{gray}{gray}{green}     &   Test        \\
    \end{tblr}
\end{table}
\end{document}
  • In comparison with your code is definition of semaphore (named \semafor) much shorter and simpler.
  • Definition of \semafore contain also option `baseline, which vertical shift image baseline so, that image is vertically centered with vertical center of adjacent cells.
  • For table is used tabularray package, which enable by default insert the same vertical space below and above cells contents.
  • For align text in the second column is used \RaggedRigh instruction. If you prefer horizontally centered text, replace cmd={\Raggedright} with c and than remove code line row{1} = {cmd={\Centering}}, too.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .