csv 파일에서 입력을 받아 이를 사용하여 tikz에서 맞춤형 테이블을 만듭니다.

csv 파일에서 입력을 받아 이를 사용하여 tikz에서 맞춤형 테이블을 만듭니다.

Scott, William, Todd, Esben, Martin, Jesper, Alexander WL과 같은 CSV 파일이 있습니다.

지금 이름은 이 줄에 써있어요

\aebuildtable{20}{Scott,William,Todd,Esben, Martin, Jesper, Alexander W.L}

csv 파일을 포함하고 싶으면 이름이 자동으로 테이블에 기록됩니다.

다음 코드가 있습니다.

\documentclass{article}
 \usepackage{geometry}
  \geometry{
  a4paper,
  total={210mm,297mm},
  left=5mm,
  right=5mm,
  top=10mm,
  bottom=10mm,
  }

\usepackage{tikz}
\usetikzlibrary{calc}
\thispagestyle{empty}
\def\aeunit{0.25cm}
\newsavebox\tictactoebox
\begin{lrbox}\tictactoebox
  \begin{tikzpicture}[x=\aeunit-0.4pt/3,
                      y=\aeunit-0.4pt/3,
                      every node/.style={outer sep=0pt,inner sep=0pt,minimum size=\aeunit-0.4pt},
                      baseline={($(current bounding box.center)+(0,-\aeunit/2)$)},
                     ]
    \draw    (0,0) rectangle (3,3);
    \foreach \myn in {0,1,...,3}
      {    \draw (0,\myn) -- (3,\myn); }
    \foreach \myn in {0,1,...,3}
      {    \draw (\myn,0) -- (\myn,3); }
  \end{tikzpicture}
\end{lrbox}

%% draw the extended vertical lines between marked columns
%% #1 column where to draw vertical line                  
\newcommand\aeDrawBorderAt[1]{%%
  \coordinate (B/C#1/top) at (R1/C#1);
  \coordinate (B/C#1/bot) at (R\aeMaxRowCount/C#1|-R\aeMaxRowCount/bot);
  \draw[blue,line width=0.6pt]
    (B/C#1/top)
    ++
    (0,4pt+\baselineskip)
    --
    (B/C#1/bot);
  }

%% label the columns              
%% #1 left column number          
%% #2 right column number         
%% #3 content for labeling columns
\newcommand\aeLabelColumns[3]{%%
  \path (R1/C#1) -- (R1/C#2) node[midway,above,yshift=0pt] {#3};
  \aeDrawBorderAt{#1}
  %\aeDrawBorderAt{#2}
}

%% #1 = number of columns to create
%% #2 = list of names              
\newcommand\aebuildtable[2]{%%
  \foreach \myn [count=\mycnt] in {#2}
  {
    %% previous value 
    \pgfmathsetmacro\myp{int(\mycnt-1)}
    %% set nodes that fix each row
    \ifnum\mycnt=1\relax
      \coordinate (R\mycnt) at (0,\mycnt-1);
    \else                   
      \coordinate (R\mycnt) at (R\myp/bot);
    \fi
    %% a coordinate for the bottom of each row
    \coordinate (R\mycnt/bot)  at ($(R\mycnt)+(0,-3*\aeunit)$);
    %% node for name:
    \node[anchor=north east,outer sep=0pt] (N\mycnt) at ($(R\mycnt)+(-4pt,-\aeunit/2)$) {\myn};

    \draw[blue,line width=0.6pt] ($(R\mycnt)+(0,-\aeunit/2 +3.3)$) -- ($(R\mycnt)+(-80pt,-\aeunit/2 +3.3)$);

    \foreach \mycol in {0,...,#1}
    {
      \coordinate (R\mycnt/C\mycol) at ($(R\mycnt)+({\mycol*(\aeunit*3)},0)$);
      \node[outer sep=0pt,
            inner sep=0pt,
            anchor=north west,]  
           at (R\mycnt/C\mycol.north west) {\usebox\tictactoebox};
    }
    \xdef\aeMaxRowCount{\mycnt}
  }
}

\begin{document}

\begin{tikzpicture}

  \aebuildtable{20}{Scott,William,Todd,Esben, Martin, Jesper, Alexander W.L}

  \aeLabelColumns{0}{9}{alm. \o l - 6,75kr}
  \aeLabelColumns{9}{15}{special \o l - 7,75kr}
  \aeLabelColumns{15}{20}{guld \o l - 10kr}

\end{tikzpicture}



\end{document}

관련 정보