2

I would like to have the same result as the following picture

enter image description here

My current result:

enter image description here

I thought that I could use \n to get the right item in the list Mylist, but I didn't find how to get an item in a list. Any idea?

My code:

%%%%%%%%%%%%%%%%%% PACKAGE %%%%%%%%%%%%%%%%%%
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage{tgadventor}
\usepackage{sansmath}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage{tikz}
%%%%%%%%%%%%%%%%%% INPUT %%%%%%%%%%%%%%%%%%
%\input{preamble.tex}
%\input{parameters.tex}

%\input{types/f2d_fig}
%%%%%%%%%%%%%%%%%% SETUP %%%%%%%%%%%%%%%%%%
\tikzset{graphtikz/.style={font={\sansmath\sffamily\large}, line width=0.4mm, line cap=round, line join=round, >=latex, x=1.0cm, y=1.0cm,}}

\def\MyList{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Z}

%%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}[graphtikz, font={\sansmath\sffamily\Large}, scale=1]
    %%%     vertical segment
    \foreach \x in {0,...,5}    
        {
        \draw[shift={(\x*2,0)},color=black!80] (0,0) -- (0,11.5);
        }
    %%%     horizontal segment
    \foreach \x in {0,...,3}
        {
        \draw[shift={(0,\x*2)},color=black!80] (28:-0.5) -- (0,0) -- (10,5) -- +(28:0.5);
        }
    %%%     Node
    \foreach \y in {0,...,3}
        {
        \foreach \x in {0,...,5}
            {
            \def\n{(\y*6)+\x}
            \draw 
            (\x*2,\y*2+\x) node[above left,] {\n};
            }
        }
\end{tikzpicture}
\end{document}
Nilcouv
  • 539

1 Answers1

3

Like this? It is not necessary to define \MyList, you can use a \Alph{<counter>} here. And of course the counter has to increase with decreasing \y.

\documentclass[border=3mm]{standalone}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage{tgadventor}
\usepackage{sansmath}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage{tikz}
%%%%%%%%%%%%%%%%%% INPUT %%%%%%%%%%%%%%%%%%
%\input{preamble.tex}
%\input{parameters.tex}

%\input{types/f2d_fig}
%%%%%%%%%%%%%%%%%% SETUP %%%%%%%%%%%%%%%%%%
\tikzset{graphtikz/.style={font={\sansmath\sffamily\large}, line width=0.4mm, line cap=round, line join=round, >=latex, x=1.0cm, y=1.0cm,}}

%\def\MyList{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Z}
\newcounter{iaux}
%%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}[graphtikz, font={\sansmath\sffamily\Large}, scale=1]
    %%%     vertical segment
    \foreach \x in {0,...,5}    
        {
        \draw[shift={(\x*2,0)},color=black!80] (0,0) -- (0,11.5);
        }
    %%%     horizontal segment
    \foreach \x in {0,...,3}
        {
        \draw[shift={(0,\x*2)},color=black!80] (28:-0.5) -- (0,0) -- (10,5) -- +(28:0.5);
        }
    %%%     Node
    \foreach \y in {0,...,3}
        {
        \foreach \x in {0,...,5}
            {
            \pgfmathtruncatemacro{\iaux}{((3-\y)*6)+\x+1}
            \setcounter{iaux}{\iaux}
            \draw 
            (\x*2,\y*2+\x) node[above left,] {\Alph{iaux}};
            }
        }
\end{tikzpicture}
\end{document}

enter image description here

If you want to work with your list, you need to wrap the entries into quotes. You can either do that by hand or let LaTeX do it for you.

\documentclass[border=3mm]{standalone}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage{tgadventor}
\usepackage{sansmath}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage{tikz}
%%%%%%%%%%%%%%%%%% INPUT %%%%%%%%%%%%%%%%%%
%\input{preamble.tex}
%\input{parameters.tex}

%\input{types/f2d_fig}
%%%%%%%%%%%%%%%%%% SETUP %%%%%%%%%%%%%%%%%%
\tikzset{graphtikz/.style={font={\sansmath\sffamily\large}, line width=0.4mm, line cap=round, line join=round, >=latex, x=1.0cm, y=1.0cm,}}

\def\MyList{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Z}
% from https://tex.stackexchange.com/a/225192
\def\addquotes#1,#2\relax{"#1",\if\relax#2\relax\else\addquotes#2\relax\fi}

%%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}[graphtikz, font={\sansmath\sffamily\Large}, scale=1]
    %%%     vertical segment
    \foreach \x in {0,...,5}    
        {
        \draw[shift={(\x*2,0)},color=black!80] (0,0) -- (0,11.5);
        }
    %%%     horizontal segment
    \foreach \x in {0,...,3}
        {
        \draw[shift={(0,\x*2)},color=black!80] (28:-0.5) -- (0,0) -- (10,5) -- +(28:0.5);
        }
    %%%     Node
    \foreach \y in {0,...,3}
        {
        \foreach \x in {0,...,5}
            {
            \pgfmathtruncatemacro{\iaux}{((3-\y)*6)+\x+1}
            \pgfmathsetmacro\mychar{{\expandafter\addquotes\MyList,\relax}[\iaux-1]}%
            \draw 
            (\x*2,\y*2+\x) node[above left,] {\mychar};
            }
        }
\end{tikzpicture}
\end{document}