使用 tikz 在表格内创建图表

使用 tikz 在表格内创建图表

我想使用乳胶创建相同的单词表。

\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.95\linewidth}{|X|X|}
    \centering
\hline
1 NO \newline POVERTY \newline
\sdgarr{red}{45}
& 
2 ZERO  \newline Hunger \newline
\sdgcir{gray}
\\

\hline
\end{tabularx}


\end{document}

在此处输入图片描述

答案1

编辑: 考虑我的建议从我的回答和你的下一个问题

您可能喜欢以下解决方案:

在此处输入图片描述

\documentclass[table]{report}
\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=2, line join=round,line cap=round]},
         rotate around={#2:(0,0)}]  (-0.4\linewidth,0) -- (0.4\linewidth,0);}
               }}
% circle fill, meaning zero?
\newcommand{\zero}{\centerline{
\tikz[baseline]{\node[circle, fill=gray, minimum size=0.8\linewidth] {};}
                  }}
% columns headers
\newcommand{\cellhead}[2]{\smallskip
    \begin{tabular}[t]{@{} >{\sffamily\bfseries}l @{\,}
                           >{\sffamily\bfseries}l
                       @{} }
    \multirow[b]{2}{*}{\scalebox{2.8}{#1}} &   {\makecell[lt]{#2}}
    \end{tabular}   }  


\begin{document}
    \begin{center}
    \setcellgapes{3pt}
    \makegapedcells
    \setlength\arrayrulewidth{1pt}
    \arrayrulecolor{cyan}
\begin{tabularx}{\linewidth}{|X|X|X|}
    \hline
\cellhead{1}{NO\\ POVERTY}
\uparr{red}
    &   \cellhead{2}{ZERO\\ HUNGER}
        \zero
        &   \cellhead{3}{WHAT\\ EVER}
            \downarr{blue} \\
    \hline
\end{tabularx}
    \end{center}
\end{document}

正如您所注意到的,上面的解决方案定义了三个命令(从头开始),它们简化了表格单元格的形成。箭头命令可以单独定义它们的颜色。

答案2

在此处输入图片描述

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

% New Commands
\newcommand{\sdgarr}{
    \tikz \draw[-{Straight Barb[line width=.2cm,line join=round,line cap=round]},line width=.2cm,color=red,line cap=round] (0,0) - - (1,1);
}
\newcommand{\sdgcir}[1]{
    \tikz \draw[fill=#1,color=#1] (0,0) circle (15pt);
}
\renewcommand\theadalign{bl}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}
\begin{tabular}{|L{1in}|p{1in}|}
%    \centering
{\bfseries\Huge 1} \thead{NO \\ POVERTY }
\centering\sdgarr
& 
\thead{2 ZERO  \\ Hunger \\
\sdgcir{gray}}\\
\end{tabular}


\end{document}

相关内容