将列表显示为节点标签

将列表显示为节点标签

我希望得到与下图相同的结果

在此处输入图片描述

我目前的结果:

在此处输入图片描述

我以为我可以用来\n获取列表中的正确项目Mylist,但我没有找到如何获取列表中的项目。有什么想法吗?

我的代码:

%%%%%%%%%%%%%%%%%% 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}

答案1

像这样?没有必要定义\MyList,你可以\Alph{<counter>}在这里使用。当然,计数器必须随着的减少而增加\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}

在此处输入图片描述

如果要处理列表,则需要将条目括在引号中。您可以手动执行此操作,也可以让 LaTeX 为您执行此操作。

\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}

相关内容