Catchfile의 결과가 tikzpicture 환경 내에서 작동하지 않습니다.

Catchfile의 결과가 tikzpicture 환경 내에서 작동하지 않습니다.

이에 대한 후속 조치입니다질문. 외부 파일의 데이터를 사용하여 그래프로 표시할 점을 가져오려고 합니다. 세로 좌표는 국가, 가로 좌표는 연도입니다. 이것이 작동하려면 axis상징적 좌표로 국가 목록을 환경에 제공해야 하는데 이것이 문제가 되는 부분입니다.

아래 MWE의 첫 번째 tikzpicture에서 국가 목록을 수동으로 제공했는데 모든 것이 정상입니다. 두 번째 tikz그림에서는 패키지 \CatchFileDef의 명령을 사용하여 외부 파일에서 로드된 목록을 제공합니다 catchfile. 명령에 \listcountries내가 수동으로 넣은 텍스트(예: AUT,GER,FRA)와 정확히 동일한 텍스트가 포함되어 있는 것처럼 보이더라도 이로 인해 오류가 발생합니다.

\CatchFileDef이 맥락에서 왜 작동하지 않는지 설명해 주시겠습니까 ?

\documentclass{standalone}
\usepackage{filecontents,catchfile}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\usepackage{pgfplotstable}

\begin{filecontents}{testcountries.txt}
AUT,GER,FRA
\end{filecontents}

\begin{filecontents}{CountryYears.csv}
    #########################################################
    country,year
    AUT,1998
    AUT,1999
    AUT,2000
    GER,1999
    GER,2000
    GER,2001
    GER,2002
    FRA,2000
    FRA,2001
    FRA,2002
    FRA,2003
    #########################################################
\end{filecontents}

\begin{document}
    \pgfplotstableset{columns/country/.style={string type}}
    \pgfplotstableread[col sep=comma]{CountryYears.csv}\loadeddata

    \CatchFileDef{\listcountries}{testcountries.txt}{}

    This is the list of countries from testcountries.txt:   \listcountries 

    \bigskip

    \begin{tikzpicture}
    \begin{axis}[symbolic y coords={AUT,GER,FRA
    },ytick=data,
    x tick label style={/pgf/number format/.cd,%
        scaled x ticks = false,
        set thousands separator={},
        fixed},]
    \addplot[only marks] table[x=year,y=country] \loadeddata;
    \end{axis}
    \end{tikzpicture}

    \begin{tikzpicture}
    \begin{axis}[symbolic y coords={\listcountries
        },ytick=data,
    x tick label style={/pgf/number format/.cd,%
        scaled x ticks = false,
        set thousands separator={},
        fixed},]
    \addplot[only marks] table[x=year,y=country] \loadeddata;
    \end{axis}
    \end{tikzpicture}

\end{document}

답변1

인수는 확장되지 않습니다. \begin{axis}옵션을 흡수하기 전에 확장해야 합니다 .

\documentclass{standalone}
\usepackage{filecontents,catchfile}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\usepackage{pgfplotstable}

\begin{filecontents}{testcountries.txt}
AUT,GER,FRA
\end{filecontents}

\begin{filecontents}{CountryYears.csv}
    country,year
    AUT,1998
    AUT,1999
    AUT,2000
    GER,1999
    GER,2000
    GER,2001
    GER,2002
    FRA,2000
    FRA,2001
    FRA,2002
    FRA,2003
\end{filecontents}

\begin{document}
    \pgfplotstableset{columns/country/.style={string type}}
    \pgfplotstableread[col sep=comma]{CountryYears.csv}\loadeddata

    \CatchFileDef{\listcountries}{testcountries.txt}{}

    This is the list of countries from testcountries.txt:   \listcountries 

    \bigskip

    \begin{tikzpicture}
    \begin{axis}[
      symbolic y coords={AUT,GER,FRA},
      ytick=data,
      x tick label style={
        /pgf/number format/.cd,
        scaled x ticks = false,
        set thousands separator={},
        fixed
      },
    ]
    \addplot[only marks] table[x=year,y=country] \loadeddata;
    \end{axis}
    \end{tikzpicture}

    \begin{tikzpicture}
    \begingroup\edef\x{\endgroup
      \noexpand\begin{axis}[
        symbolic y coords={\unexpanded\expandafter{\listcountries}},
        ytick=data,
        x tick label style={
          /pgf/number format/.cd,%
          scaled x ticks = false,
          set thousands separator={},
          fixed
        },
      ]}\x
    \addplot[only marks] table[x=year,y=country] \loadeddata;
    \end{axis}
    \end{tikzpicture}

\end{document}

관련 정보