TransWikia.com

Create graphs inside table using tikz with many rows and columns

TeX - LaTeX Asked on December 28, 2020

I want to replicate the table (3 by 6), and it should be sizable in order to get inside mini page.

documentclass{report}
usepackage{tikz}
usetikzlibrary{arrows.meta}
usepackage{tabularx}


% New Commands
newcommand{sdgarr}[2]{
    tikz draw[-{Straight Barb[line width=.2cm,line join=round,line cap=round]},line width=.2cm,color=#2,line cap=round,rotate=#1-45] (0,0) - - (1,1);
}
newcommand{sdgcir}[1]{
    tikz draw[fill=#1,color=#1] (0,0) circle (5pt);
}


begin{document}
begin{tabularx}{0.95linewidth}{|X|X|}
    centering
hline
1 NO newline POVERTY newline
sdgarr{red}{45}
& 
2 ZERO  newline Hunger newline
sdgcir{gray}


hline
end{tabularx}


end{document}

I asked similar question, but I was not clear enough.

Create graphs inside table using tikz

enter image description here

One Answer

Edit:

As promised I wee bit improve suggest solution:

  • new commands definitions
  • align of images
  • I still left to write correct text in table as well select desired images in cells to OP (this now should not be big deal)

enter image description here

documentclass[table]{report}
usepackage{geometry}
usepackage{tikz}
usetikzlibrary{arrows.meta}
usepackage{makecell, multirow, tabularx}
usepackage{graphicx}

% arrows
newcommand{rotarr}[2]{centerline{
tikz[baseline]{%
    path[draw=#1,line width=3mm, line join=round,line cap=round,
         -{Straight Barb[scale=1.2, line join=round,line cap=round]},
         rotate around={#2:(0,0)}]  (-0.4linewidth,0) -- (0.4linewidth,0);}
               }}
% circle fill, meaning zero?
newcommand{zero}{centerline{
tikz[baseline]{node[circle, fill=gray, minimum size=0.8linewidth] {};}
                  }}
% columns headers                  
newcommand{cellhead}[2]{smallskipcenterline{
    begin{tabular}[t]{@{} >{sffamilybfseries}l @{,}
                           >{sffamilybfseries}l
                       @{} }
    multirow[b]{2}{*}{scalebox{2.8}{#1}} &   {makecell[lt]{#2}}
    end{tabular}   }  }

begin{document}
    begin{center}
    setlengtharrayrulewidth{1pt}
    arrayrulecolor{cyan}
begin{tabularx}{linewidth}{|*{6}{X|}}
% first two-line row
   hline
cellhead{1}{NOPOVERTY}
    &   cellhead{2}{ZEROHUNGER}
        &   cellhead{3}{WHATEVER}
            &   cellhead{4}{NOPOVERTY}
                &   cellhead{5}{ZEROHUNGER}
                    &   cellhead{6}{WHATEVERNEWER}  
rotarr{red}{45}
    &   zero
        &   rotarr{purple}{-90}
            &   rotarr{orange}{0}
                &   rotarr{teal}{90}
                    &   rotarr{orange}{0}              
% second two-line row
    hline
cellhead{7}{NOPOVERTY}
    &   cellhead{8}{ZEROHUNGER}
        &   cellhead{9}{WHATEVER}
            &   cellhead{10}{NOPOVERTY}
                &   cellhead{11}{ZEROHUNGER}
                    &   cellhead{12}{WHATEVERNEWER}  
rotarr{red}{45}
    &   zero
        &   rotarr{purple}{-90}
            &   rotarr{orange}{0}
                &   rotarr{teal}{90}
                    &   rotarr{orange}{0}              
    hline
end{tabularx}
    end{center}
end{document}
  • it is not clear, what you mean with "sizable":
    • the font size used in the table must be set manually so that the text doesn't protrude from the cells
    • size of images are now determined by cell width, consequently their sizes will always adopted to cells' widths
  • that images are aligned as desired, they are now set in separate row. So far that was only way that I was able to achieve this.

Answered by Zarko on December 28, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP