tikzpicture가 포함된 해시태그 라벨

tikzpicture가 포함된 해시태그 라벨

아래 트리와 작동 중인 트리를 컴파일하려고 합니다. 문제는 DP 또는 LP의 라벨을 \#P(예: ) 로 변경할 때마다 \node(\#P) {\#P}; \#다음과 같은 오류 메시지가 표시된다는 것입니다.

! Missing \endcsname inserted.
<to be read again>
\#
l.17 ...LP}; L [.YP Y [.FP ] ] ] ] ] ] ]
]
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.
Missing character: There is no # in font nullfont!
Missing character: There is no P in font nullfont!
\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}

\usepackage{tikz-qtree-compat}

\tikzset{every tree node/.style={baseline=(top.base), level distance=2em, sibling distance=4em, align=center, parent anchor=south, child anchor=north, anchor=north}, sibling distance=15pt}

\usetikzlibrary{positioning} 

\begin{document}

\begin{tikzpicture}  [inv/.style={overlay, coordinate  }]  

\Tree [.XP X [.ZP Z [.\node(DP) {DP}; D    [.\node(LP) {LP}; L      [.YP Y [.FP     ] ] ] ] ]  ] ] ] 

\node [ right=1cm of DP,font=\itshape] (X) {Blah};

\draw[<-] (X.west) -- (DP);

\node [ right=1cm of LP,font=\itshape] (X) {Blah};

\draw[<-] (X.west) -- (LP);    

\end{tikzpicture}

\end{document}

산출

답변1

#인쇄하려면 이스케이프해야 하는 TeX의 특수 문자입니다. 따라서 일반 텍스트에서는 이스케이프 처리해야 합니다. 단, 노드 이름에는 매크로가 허용되지 않으므로 \#노드 이름에는 사용할 수 없습니다.

따라서 노드 이름에 x교체와 같은 다른 문자를 사용하는 것이 좋습니다 \#(코드에서 내부적으로만 사용되며 어쨌든 조판되지 않음).

쉼표, 세미콜론, 하이픈, 중괄호, 점, 괄호, 슬래시, 대시 등을 포함한 대부분의 "특수 문자 [...]"도 포함됩니다(Ti 인용).케이Z 매뉴얼)은 노드 이름에 사용할 수 없습니다.

변경에 대해서는 \catcode다음을 참조하십시오.여기.


편집하다가능한 해결 방법: 1) 노드 이름을 텍스트와 다르게 지정하세요. 2) 노드 이름과 노드 텍스트가 동일해야 하는 경우 매크로를 사용하여 다음 xD으로 바꿀 수 있습니다 \#D.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\usepackage{xstring}
\newcommand{\xtohash}[1]{\StrSubstitute[0]{#1}{x}{\#}}

\begin{document}

\begin{tikzpicture}

\node at (0,0) (xD) {\#D};

\node at (0,1) (xD) {\xtohash{xD}};

\end{tikzpicture}

\end{document}

관련 정보