TikZ를 사용하여 억양 묘사

TikZ를 사용하여 억양 묘사

나는 문구나 문장(억양)에 대한 피치 패턴을 표현하기 위해 TikZ를 사용하는 방법을 조사하고 있습니다.

나는 첨부된 MWE에서와 같이 이미 몇 가지 유용한 결과를 생성했습니다(비록 1.1에서는 기준선이 레벨업되지 않는 것 같지만).

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass[a4paper,12pt, oneside]{article}

\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text, Scale=MatchLowercase}
\setmainfont{Charis SIL}

\usepackage{tikz}

\begin{document}

\section{Marking intonation using TikZ}

\subsection{Setting words on different levels}

\begin{table}[hbtp]
\begin{tabular}{ll}
\cline{1-1} \noalign{\smallskip}
\tikz[x=1mm,y=1mm,baseline=12] \draw (0,10) node {\underline{Where}} (10,2) node {are} (20,2) node {you} (30,6) node {\underline{go}} (40,0) node{ing?}; & \textit{neutral/default - stress represented by underlining}\\
\cline{1-1} \noalign{\smallskip}
\tikz[x=1mm,y=1mm,baseline=12] \draw (0,0) node {Where} (10,10) node {\underline{are}} (20,5) node {you} (30,2) node {go} (40,0) node{ing?}; & \textit{ e.g. in response to ``I'm not going to the shops after all.''}\\
\cline{1-1}
\end{tabular}
\end{table}

Why do ``are'' and ``you'' in the first example appear on slightly
different levels, even though they are both set to 1mm on the y axis? 
Likewise for ``where'' and ``ing'' in the second example.

I'm not sure I'm using ``baseline'' properly here!

\subsection{As above, but boxed}

\begin{tikzpicture}
\node[draw] at (0,1) {\underline{Where}};
\node[draw] at (1,0.1) {are};
\node[draw] at (2,0.1) {you};
\node[draw] at (3,0.6) {\underline{go}};
\node[draw] at (4,0) {ing?};
\end{tikzpicture}\
Still have to figure out the difference between ``\textbackslash draw node'' and ``\textbackslash node[draw]''!

\subsection{Graphical contour}

\begin{table}[hbtp]
\begin{tabular}{l}
\tikz[x=1mm,y=1mm,rounded corners=2mm] \draw[very thick, gray](0,10)--(10,2)--(20,2){[red]--(30,6)--(40,0)}; \\
Where are you~~~going?
\end{tabular}
\end{table}

\begin{table}[hbtp]
\begin{tabular}{l}
\tikz[x=1mm,y=1mm,rounded corners=2mm] \draw[very thick, gray](0,10)--(12,2)--(23,2){[red]--(26,6)--(35,0)}; \\
Where are you going?
\end{tabular}
\end{table}

This is preferable to setting the individual words on different levels, but
requires trial and error in (i) matching the length of the whole contour to
the utterance, and (ii) spreading the parts of the contour to match the words
of the utterance, either by spacing the words (first example) or adjusting the
contour points (second example).

\end{document}

그러나 제가 가장 궁금해하는 점은 1.3의 문제를 해결할 수 있는 방법이 있는 사람이 있느냐는 것입니다. 여기에는 윤곽선을 단어에 맞추는 시행착오가 포함되며, 특정 윤곽선 좌표를 특정 음절에 고정할 수 있는 방법이 있는지 궁금합니다. 선을 노드에 연결할 수 있다는 것을 알고 있지만 선을 노드 위에 "떠다니는" 방법을 찾지 못했습니다. 텍스트 줄을 입력할 때 앵커 포인트로 표시하고 그 사이에 윤곽선을 그리는 방법에 대한 제안 사항이 있습니까?

여기에 이미지 설명을 입력하세요

답변1

Matthew Leingang의 답변에 이어 구문 설탕과 관련된 동일한 접근 방식이 있습니다. 물건을 어지럽히 \catcode기 때문에 주의가 필요합니다.

\documentclass{standalone}
\usepackage{tikz}

\newcount\contourmarkcount
\newdimen\contourraise

{\catcode`\|=13
\gdef\installbarmark#1\ignorespaces{%
    #1\ignorespaces%
    \catcode`\|=13%
    \global\contourmarkcount=0\relax%
    \global\def\lastmarkshift{0}%
    \let|=\marktext}%
}


\def\star{*}
\newcommand\marktext[1][*]{%
    \def\markshift{#1}%
    % When not followed by the optional argument
    % the contour mark is set at the previous height.
    \ifx\markshift\star
        \let\markshift=\lastmarkshift%
    \fi
    \global\advance\contourmarkcount by1\relax%
    \xdef\tmpmark{\the\contourmarkcount}%
    \tikz[remember picture, overlay, y=\pgfkeysvalueof{/tikz/contour scale}]
        \path [yshift=\contourraise, shift={(0,\markshift)}]
                coordinate (\contourmarkprefix-\tmpmark);%
    \global\contourmarkcount=\tmpmark\relax% 
    \global\let\lastmarkshift=\markshift%
}


\tikzset{
    intonation contour/.style={%
        execute at begin node={%
            \installbarmark%
        },
        append after command={%
            \pgfextra{%
                \ifnum\contourmarkcount>1
                    \draw [contour] (\contourmarkprefix-1)
                        \foreach \y in {2,...,\the\contourmarkcount}{ -- (\contourmarkprefix-\y) };
                \fi
            }
        }
    },
    % How far above the base line of the text,
    raise contour/.code=\pgfmathsetlength\contourraise{#1},
    % The `scale' for the values in the contour height specification
    contour scale/.initial=3pt,
    % The prefix for the contour marks.
    contour mark prefix/.code=\xdef\contourmarkprefix{#1},
    contour mark prefix=intonation contour,
    contour/.style={
        draw, 
        rounded corners=1ex,
    }           
}

\begin{document}

\begin{tikzpicture}[remember picture]

\node [intonation contour, raise contour=0.5cm] 
    {|[10]Where |[3]are |[3]you |[5]go|[2]ing|[0]?};

\end{tikzpicture}

\begin{tikzpicture}[remember picture]

\node [intonation contour, raise contour=0.5cm, contour mark prefix=my contour] 
    {|[2]I  |am  |[7]fina|lly |[4]go|ing |[2]home|[0].};

\path [draw=red, ->] ([yshift=0.25cm]my contour-2) -- ([yshift=0.25cm]my contour-3)
        node [midway, left] {\tiny rising};

\path [draw=red, ->] ([yshift=0.25cm]my contour-4) -- ([yshift=0.25cm]my contour-5)
    node [midway, right] {\tiny falling};
\end{tikzpicture}

\end{document}

여기에 이미지 설명을 입력하세요

그리고 재미삼아 여기에 사용되지 않는 버전이 있으므로 remember picture두 개의 컴파일이 필요하지 않습니다. 또한 카테고리 코드를 조작하는 일도 없습니다. 불행히도 조금 더 복잡하고 글자가 모두 별도의 상자에 들어 있기 때문에 이상적으로 조판되지 않습니다.

편집하다좀 더 다양한 기능이 구현되었지만 결과적으로 조금 더 복잡해졌습니다.

\documentclass{standalone}
\usepackage{tikz}

\newdimen\contourraise

\tikzset{
    % How far above the base line of the text,
    raise contour/.code=\pgfmathsetlength\contourraise{#1},
    % The `scale' for the values in the contour height specification
    contour scale/.initial=3pt,
    % The prefix for the contour marks.
    contour mark prefix/.code=\xdef\contourmarkprefix{#1},
    contour mark prefix=contour,
    % The style for the contour path
    contour/.style={
        draw, 
        rounded corners=1ex,
    },
    % The style for the token nodes
    contour token/.style={
        anchor=base west, 
        inner sep=0pt,
        text depth=0.6ex, % controls underline depth
    },
    contour underline/.style={
        draw
    },
    % The character to insert a mark (use with care)
    contour mark character/.store in=\contourmarkchar,
    contour mark character=|
}


\makeatletter

\def\at@{@}

\newcount\lasttokennumber
\newcount\currenttokennumber
\newcount\contourmarkcount
\newcount\contourtokenunderlinestate
\newcommand\contour[2][]{%
    \begin{scope}[#1]
        \coordinate (token-0);
        \currenttokennumber=0\relax%
        \lasttokennumber=0\relax%
        \contourmarkcount=0\relax%
        \def\lastcontourheight{0}%
        \contourtokenunderlinestate=0\relax%
        \@contour#2@%
}


% Must check for a spaces
\def\@contour{\futurelet\@token\@checkforspace}

\def\@uscore{_}
\def\@checkforspace{%
    \ifx\@token\@sptoken%
        \let\@next=\@replacespace%
    \else%
        \if\@token\contourmarkchar%
            \let\@next=\@contour@insertmark
        \else%
            \if\@token\@uscore
                \let\@next=\@contourtoggleunderline%
            \else%
                \let\@next=\@@contour%
            \fi%
        \fi%
    \fi%
    \@next%
}

\def\@contourtoggleunderline#1{%
    \advance\contourtokenunderlinestate by1\relax
    \ifnum\contourtokenunderlinestate>3\relax%
        \contourtokenunderlinestate=0\relax%
    \fi%
    \@contour%
}

\def\@contour@insertmark{%
    \afterassignment\@@contour@insertmark\let\@token=%
}

\def\@@contour@insertmark{%
    \futurelet\@token\@@@contour@insertmark}%

\def\@@@contour@insertmark{%
    \if\@token[%
        \let\@next=\@@@@contour@insertmark%
    \else%
        \let\currentcontourheight=\lastcontourheight%
        \let\@next=\@@@@@contour@insertmark%
    \fi%
    \@next%
}

\def\@@@@contour@insertmark[#1]{%
    \def\@tmp{#1}%
    \ifx\@tmp\@empty%
        \let\currentcontourheight=\lastcontourheight%
    \else%
        \def\currentcontourheight{#1}%
    \fi%
    \@@@@@contour@insertmark}

\def\@@@@@contour@insertmark{%
    \advance\contourmarkcount by1\relax%
    % Code for inserting mark
    \coordinate (\contourmarkprefix-\the\contourmarkcount)
        at ([yshift=\contourraise, y=\pgfkeysvalueof{/tikz/contour scale}, 
        shift={(0,\currentcontourheight)}]token-\the\currenttokennumber.base east);
    %
    \let\lastcontourheight=\currentcontourheight
\@contour}

\def\customspace{{\hbox to 1ex{\hfill}}}

\def\@replacespace#1{%
    \@contour\customspace#1%
}

\def\@@contour#1{%
    \def\@token{#1}%
    \if\@token\at@
        \let\@next=\@@@contour%
    \else%
        \lasttokennumber=\currenttokennumber%
        \advance\currenttokennumber by1%
        % Code for typesetting token
        \node [contour token/.try] at (token-\the\lasttokennumber.base east) (token-\the\currenttokennumber) {\@token};
        % Manage underline state
        \ifnum\contourtokenunderlinestate=1\relax%
            \coordinate (underline start) at (token-\the\currenttokennumber.south west);
            \contourtokenunderlinestate=2\relax%
        \else
            \ifnum\contourtokenunderlinestate=3\relax%
                \coordinate (underline end) at (token-\the\currenttokennumber.south west);
                \draw (underline start) -- (underline end);
                \contourtokenunderlinestate=0\relax
            \fi%
        \fi%
        \let\@next=\@contour
        %
    \fi%
    \@next%
}
\def\@@@contour{%
    \ifnum\contourmarkcount>1
        % Code for drawing contour
        \draw [contour] (\contourmarkprefix-1)
            \foreach \y in {2,...,\the\contourmarkcount}{ -- (\contourmarkprefix-\y) };
        %
    \fi%
    \end{scope}%
}

\makeatother

\begin{document}

\begin{tikzpicture}[baseline={(0,-0.25)}]

    \contour[raise contour=0.5cm]
        {|[10]Where |[3]are |[3]_you_ |[5]go|[2]ing|[0]?}

\end{tikzpicture} 


\begin{tikzpicture}[baseline={(0,-0.25)}]

\contour[
    raise contour=0.5cm, 
    contour mark prefix=my contour, 
    contour/.style={
        thick, 
        rounded corners=1mm,
        line cap=round,
        dotted},
    contour mark character=*] 
    {*[2]I *am  *[7]_{fi}na*lly_ *[4]go*ing *[2]home*[0].};

\path [draw=red, ->] ([yshift=0.25cm]my contour-2) -- ([yshift=0.25cm]my contour-3)
        node [midway, left] {\tiny rising};

\path [draw=red, ->] ([yshift=0.25cm]my contour-4) -- ([yshift=0.25cm]my contour-5)
    node [midway, right] {\tiny falling};

\path (0,-0.25);
\end{tikzpicture}

\end{document}

여기에 이미지 설명을 입력하세요

편집하다:위에 제시된 모든 사용 사례를 포괄하는 향상된 버전입니다.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{fit}

\newdimen\contourraise
\newdimen\contourspacetokenwidth
\newcount\lasttokennumber
\newcount\currenttokennumber
\newcount\contourmarkcount
\newcount\contourtokenunderlinestate
\newbox\contourbox

\tikzset{
    tight fit/.style={
        inner sep=0pt,
        outer sep=0pt,
    },
    %
    %
    % How far above the reference anchor of the text,
    contour raise/.code=\pgfmathsetlength\contourraise{#1},
    contour reference anchor/.store in=\contourreferenceanchor,
    contour reference anchor=base east,
    % The `scale' for the values in the contour height specification
    contour scale/.store in=\contourscale,
    contour scale=3pt,
    % The prefix for the contour marks.
    contour mark prefix/.store in=\contourmarkprefix,
    contour mark prefix=contour,
    % The style for the contour path
    contour/.style={
        draw, 
        rounded corners=1ex,
    },
    % The style for the token nodes
    every contour token/.style={
        anchor=base west, 
        inner sep=0pt,
    },
    contour underline/.style={
        draw
    },
    % The character to insert a mark (use with care)
    contour mark character/.store in=\contourmarkchar,
    contour mark character=|,
    % Want to change the code for contour marks? Use this key.
    contour mark code/.store in=\contourmarkcode,
    % Want to change the code for tokens? Use this key.
    contour token code/.store in=\contourtokencode,
    % Want to change the code for drawing the contour? Use this  key.
    contour code/.store in=\contourcode,
    %
    % Default stuff
    contour mark code={%
        \coordinate (\contourmarkprefix-\the\contourmarkcount)
          at ([yshift=\contourraise, y=\contourscale,               
          shift={(0,\currentcontourheight)}]token-\the\currenttokennumber.\contourreferenceanchor);
    },
    contour token code={%
        \node [every contour token/.try] at 
        (token-\the\lasttokennumber.base east) 
            (token-\the\currenttokennumber) {\token};
    },
    contour code={
        \draw [contour] (\contourmarkprefix-1)
            \foreach \y in {2,...,\the\contourmarkcount}{ -- 
                    (\contourmarkprefix-\y) };                  
    },
    %
    % Don't draw the contour.
    tokens only/.style={
        contour code={}
    },
    %
    % Only draw the contour (but the space is still used for the tokens)
    contour only/.style={
        every contour token/.append style={
            execute at begin node={\setbox\contourbox=\hbox\bgroup},
            execute at end node=\egroup\phantom{\box\contourbox}%
        },
        underline/.style={
            draw=none
        }
    },
    %
    % Make tokens follow the contour marks.
    tokens follow contour/.style={
        tokens only,
        contour token code={%
            \node [every contour token/.try, y=\contourscale] at 
                (token-\the\lasttokennumber.base east |- 
                0,\currentcontourheight) 
                (token-\the\currenttokennumber) {\token};
        },
    },
    % What style to use when drawing underline
    underline/.style={
        draw
    },
    % The underline is drawn along the south side of a node which 
    % takes this style.
    underline token/.style={
        inner ysep=1pt
    },
    % When grouping tokens (e.g., for putting box around)
    % this style is applied to a node that is fitted around the group
    token group/.style={
        inner xsep=1pt,
        inner ysep=2pt,
        rounded corners=2pt
    },
    % Draw boxes around tokens groups.
    box tokens/.style={
        token group/.append style={
            draw
        }
    },  
    % Change the width of the spaces.
    space token width/.code=\pgfmathsetlength\contourspacetokenwidth{#1},
    space token width=0.125cm
}


\makeatletter

\def\at@{@}


\newcommand\contour[2][]{%
    \begin{scope}[#1]
        \coordinate (token-0);
        \currenttokennumber=0\relax%
        \lasttokennumber=0\relax%
        \contourmarkcount=0\relax%
        \def\lastcontourheight{0}%
        \contourtokenunderlinestate=0\relax%
        \@contour#2@%
}


% Must check for a spaces
\def\@contour{\futurelet\@token\@checkforspace}

\def\@uscore{_}
\def\@checkforspace{%
    \ifx\@token\@sptoken%
        \let\@next=\@replacespace%
    \else%
        \if\@token\contourmarkchar%
            \let\@next=\@contour@insertmark
        \else%
            \if\@token\@uscore
                \let\@next=\@contourtoggleunderline%
            \else%
                \let\@next=\@@contour%
            \fi%
        \fi%
    \fi%
    \@next%
}

\def\@contourtoggleunderline#1{%
    \advance\contourtokenunderlinestate by1\relax
    \ifnum\contourtokenunderlinestate>3\relax%
        \contourtokenunderlinestate=0\relax%
    \fi%
    \@contour%
}

\def\@contour@insertmark{%
    \afterassignment\@@contour@insertmark\let\@token=%
}

\def\@@contour@insertmark{%
    \futurelet\@token\@@@contour@insertmark}%

\def\@@@contour@insertmark{%
    \if\@token[%
        \let\@next=\@@@@contour@insertmark%
    \else%
        \let\currentcontourheight=\lastcontourheight%
        \let\@next=\@@@@@contour@insertmark%
    \fi%
    \@next%
}

\def\@@@@contour@insertmark[#1]{%
    \def\@tmp{#1}%
    \ifx\@tmp\@empty%
        \let\currentcontourheight=\lastcontourheight%
    \else%
        \def\currentcontourheight{#1}%
    \fi%
    \@@@@@contour@insertmark}

\def\@@@@@contour@insertmark{%
    \advance\contourmarkcount by1\relax%
     % Code for inserting mark
    \contourmarkcode%
    \let\lastcontourheight=\currentcontourheight%
    \@contour}

\def\contourspacetoken{{\hbox to \contourspacetokenwidth{\hfill}}}

\def\@replacespace#1{%
    \@contour\contourspacetoken#1%
}

\def\@@contour#1{%
    \def\@token{#1}%
    \if\@token\at@%
        \@contourdounderline%
        \pgfutil@ifundefined{pgf@sh@ns@tokengroup}{}{%
            \node [tight fit, fit={(tokengroup)}, token group/.try] {};
            \global\let\pgf@sh@ns@tokengroup=\relax%
        }%
        \let\@next=\@@@contour%
    \else%
        \lasttokennumber=\currenttokennumber%
        \advance\currenttokennumber by1%
        \let\token=\@token%
        % Code for typesetting token
        \contourtokencode%
        % Manage underline state
        \@contourdounderline%
        \def\@@token{\contourspacetoken}%
        \ifx\@token\@@token%
            \pgfutil@ifundefined{pgf@sh@ns@tokengroup}{}{%
                \pgfutil@ifundefined{pgf@sh@ns@underline}{}{%
                    \node [tight fit, fit={(tokengroup) (underline)}] 
                    (tokengroup) 
                {};}%
                \node [tight fit, fit={(tokengroup)}, token group/.try] {};
                \global\let\pgf@sh@ns@tokengroup=\relax%
            }%
        \else
            \pgfutil@ifundefined{pgf@sh@ns@tokengroup}{%
                \node [tight fit, 
                fit={(token-\the\currenttokennumber)}] 
                (tokengroup) {};
            }{%
                \node [tight fit, 
                fit={(token-\the\currenttokennumber) 
                (tokengroup)}] 
                (tokengroup){};
            }%
        \fi%
        \let\@next=\@contour
        %
    \fi%
    \@next%
}

\def\@contourdounderline{%
    \ifcase\contourtokenunderlinestate%
     \or
         \node [tight fit, fit={(token-\the\currenttokennumber)}] 
         (underline) {};
         \contourtokenunderlinestate=2\relax%
     \or%
            \node [tight fit,fit={(token-\the\currenttokennumber) (underline)}]
            (underline) {};
     \or%
            \node [tight fit, fit={(underline)}, underline token/.try] 
            (underline) {};
         \draw [underline/.try]
                    (underline.south west) -- (underline.south east);
            \pgfutil@ifundefined{pgf@sh@ns@tokengroup}{}{%
                 \node [tight fit, fit={(tokengroup) (underline)}] 
                 (tokengroup) {};%
                 \node [tight fit, fit={(tokengroup)}, token group/.try] {};
                 \global\let\pgf@sh@ns@tokengroup=\relax%
                 \global\let\pgf@sh@ns@underline=\relax%
             }
         \contourtokenunderlinestate=0\relax
     \fi%
}
\def\@@@contour{%
    \ifnum\contourmarkcount>1
        % Code for drawing contour
        \contourcode%
    \fi%
    \end{scope}%
}

\makeatother

\begin{document}

\begin{tabular}{c}
\\
\begin{tikzpicture}
    \contour[tokens follow contour]
        {|[10]_Where_ |[3]are you |[6]_go_|[1]ing?|[0]}
\end{tikzpicture} 

\\[0.5cm]

\begin{tikzpicture}
    \contour[tokens follow contour, box tokens, space token width=0.2cm]
       {|[10]_Where_ |[3]are you |[6]_go_ |[1]ing?|[0]}
\end{tikzpicture} 

\\[0.5cm]

\begin{tikzpicture}
    \contour[contour raise=0.5cm]
        {|[10]_Where_ |[3]are you |[6]_go_|[1]ing?|[0]}
\end{tikzpicture} 


\\[0.5cm]

\begin{tikzpicture}
    \contour[contour raise=0.5cm]
        {|[10]Where |[3]are |[3]_you_ |[5]go|[2]ing?|[0]}

    \contour[contour raise=0.5cm, contour only, contour/.append style={dashed}]
            {|[0]Where |[2]are |[8]you |[2]go|[2]ing?|[1]}

\end{tikzpicture} 

\\[1cm]

\begin{tikzpicture}
\contour[tokens follow contour,
    contour mark character=*] 
    {*[2]I *am  *[7]_{fi}na*lly_ *[4]go*ing *[2]_home_*[0]};
\end{tikzpicture} 
\\[0.5cm]
\begin{tikzpicture}
\contour[
    contour raise=0.5cm, 
    contour mark prefix=my contour,
    contour/.style={
        thick, 
        rounded corners=1mm,
        line cap=round,
        dotted},
    contour mark character=*] 
    {*[2]I *am  *[7]_{fi}na*lly_ *[4]go*ing *[2]home*[0].};

\path [draw=red, ->] ([yshift=0.25cm]my contour-2) -- ([yshift=0.25cm]my 
contour-3)
        node [midway, left] {\tiny rising};

\path [draw=red, ->] ([yshift=0.25cm]my contour-4) -- ([yshift=0.25cm]my 
contour-5)
    node [midway, right] {\tiny falling};

\end{tikzpicture}

\end{tabular}
\end{document}

여기에 이미지 설명을 입력하세요

답변2

나는 유명한 것을 사용할 것입니다\tikzmark매크로를 사용하여 교차점 좌표와 결합합니다. 코드는 다음과 같습니다.

\documentclass{standalone}
\usepackage{tikz}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture,baseline] \node [anchor=base] (#1) {};}%
\tikzstyle{intonation}=[rounded corners=2mm,yshift=1.5ex]
\begin{document}

\begin{tikzpicture}[remember picture]
\node{\tikzmark{w}Where \tikzmark{a}are \tikzmark{y}you \tikzmark{g}go\tikzmark{i}ing\tikzmark{q}?};
\draw[intonation] (w |- 0,1) -- (a |- 0,0.2) -- (y |- 0,0.2) -- (g |- 0,0.6) -- (q |- 0,0);
\end{tikzpicture}

\end{document}

매크로 \tikzmark는 문서에서 호출된 지점의 좌표를 저장합니다. 그래서 노드 텍스트는 문장의 여러 지점에 , 등 이라는 \tikzmark{w}Where \tikzmark{a}are...좌표를 저장합니다 .wa

AB가 TikZ 노드 또는 좌표인 경우 는 (A |- B)수직선 A과 수평선 의 교차점입니다 B. 그래서(w |- 0,1)엑스기준선 왼쪽 지점을 조정합니다.~에어디, 그리고와이좌표 1. 이것을 변경할 수 있습니다와이다른 좌표 이름에 대해 원하는 대로 좌표를 지정합니다.

결과는 다음과 같습니다.

샘플 코드 출력

텍스트를 지정/표시하고와이-동일한 인수의 값. 그러나 이것은 가능한 구현입니다.

답변3

좌표를 올바른 위치에 배치했는지(두 지점에서 재사용했는지) 잘 모르겠지만 \zzb다음과 같습니다.

여기에 이미지 설명을 입력하세요

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\documentclass[a4paper,12pt, oneside]{article}

\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text, Scale=MatchLowercase}
\setmainfont{Charis SIL}

\makeatletter
\def\savecoordinate#1#2{\sbox0{#2}\edef#1{\strip@pt\wd0}}
\makeatother

\usepackage{tikz}

\begin{document}


\savecoordinate\zza{Where }
\savecoordinate\zzb{Where are you}
\savecoordinate\zzc{Where are you going?}

\begin{table}[hbtp]
\begin{tabular}{l}
\tikz[x=1pt,y=1mm,rounded corners=2mm] \draw[very thick, gray](0,10)--(\zza,2)--(\zzb,2)--(\zzb,6)--(\zzc,0); \\
\mbox{Where are you going?}
\end{tabular}
\end{table}

\end{document}

답변4

1.1

문제는 그렇지 않습니다 baseline. tikzpicture 환경은 상자(tex's box)를 정의합니다. 이 상자에는 깊이와 높이가 있습니다. 기본적으로 깊이는 null이고 높이는 상자의 높이입니다. 왼쪽 아래 점이 기준선을 정의하기 때문입니다. 다음 코드에서는 baseline=(current bounding box.east) 표 형식을 사용하고 싶지 않기 때문에 작성했습니다. tikz를 사용하면 물체를 배치하는 것이 매우 쉽다고 생각합니다. 텍스트가 \textit{neutral/default - stress represented by underlining}상자 중앙에 정렬됩니다.

비고 : 다음글에 가 \mbox있기 때문에 글을 넣어야 합니다 .\overful box

문제는~이다그리고로 방지됩니다 every node/.style={anchor=base}. 박스와 깊이의 문제입니다. 편지가 담긴 상자는 y깊이가 큽니다. anchor=base모든 노드 에는 동일한 기준선이 있습니다.

마지막 설명 : 표 형식과 동일한 결과를 얻기 위해 show background bottom등을 사용했습니다.

\begin{table}[hbtp]
\begin{tikzpicture}[baseline=(current bounding box.east),every node/.style={anchor=base},show background top,show background bottom]
\path (0,1) node {\underline{Where}} (1,.2) node {are} (2,.2) node {you} (3,.6) node {\underline{go}} (4,0) node{ing?}; 
\end{tikzpicture}%
\mbox{\textit{neutral/default - stress represented by underlining}}%

\begin{tikzpicture}[baseline=(current bounding box.east),every node/.style={anchor=base},show background bottom] 
    \draw (0,0) node {Where} (1,1) node {\underline{are}} (2,.5) node {you} (3,.2) node {go} (4,0) node{ing?}; 
\end{tikzpicture}%
\mbox{\textit{e.g. in response to ``I'm not going to the shops after all.''}}%
\end{table}

1.2

경로에 노드를 추가하면 이 노드는 정확히 경로의 일부가 아닙니다. 경로에 개체가 연결되어 있지만 경로의 일부 옵션이 노드에 사용되지 않습니다.

\draw node ...,\path[draw] node ... ; 는 경로를 그리기로 결정했지만 draw경로의 옵션이 draw노드의 옵션 이 아니라는 것을 의미합니다 . 경로와 노드를 그리려면 다음을 작성해야 합니다.\path[draw] node[draw] ... ;

1.3

완전한 코드와 결과

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass[a4paper,12pt, oneside]{article}

\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text, Scale=MatchLowercase}
\setmainfont{Charis SIL}

\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}

\section{Marking intonation using TikZ}

\subsection{Setting words on different levels}

\begin{table}[hbtp]
\begin{tikzpicture}[baseline=(current bounding box.east),every node/.style={anchor=base},show background top,show background bottom]
\path (0,1) node {\underline{Where}} (1,.2) node {are} (2,.2) node {you} (3,.6) node {\underline{go}} (4,0) node{ing?}; 
\end{tikzpicture}%
\mbox{\textit{neutral/default - stress represented by underlining}}%

\begin{tikzpicture}[baseline=(current bounding box.east),every node/.style={anchor=base},show background bottom] 
    \draw (0,0) node {Where} (1,1) node {\underline{are}} (2,.5) node {you} (3,.2) node {go} (4,0) node{ing?}; 
\end{tikzpicture}%
\mbox{\textit{e.g. in response to ``I'm not going to the shops after all.''}}%
\end{table}


\subsection{Final attempt}

\makeatletter
\xdef\tmp{}

\def\MarkWord(#1/#2){%
\node[anchor=base west,inner sep=0pt] (a) at (\xa,#2) {#1};
\path (a.west);\pgfgetlastxy{\xa}{\ya}
 \xdef\tmp{\tmp(\xa,#2)}%
\path (a.base east) -- ++(1 ex,0) coordinate (a);
\path (a);
\pgfgetlastxy{\xa}{\ya}
\global\let\xa\xa
}

\def\util@empty{}

\def\multiwords#1 #2\@nil{%
 \protected@edef\@temp{%
   \noexpand\MarkWord(#1)}\@temp
   \def\@nextArg{#2}%  
    \ifx\util@empty\@nextArg
       \let\next\@gobble
     \fi
   \next#2\@nil
    }

\def\MarkWords#1{% 
  \begingroup
    \path (0,0) coordinate (a);
    \xdef\xa{0}
   \let\next\multiwords
   \next#1 \@nil %    
\endgroup 
} 
\makeatother

\begin{tikzpicture}
    \MarkWords{Where/1 are/.2 you/.2 go/.6 ing?/0}
   \path[draw,red] (0,0) plot[smooth] coordinates{\tmp};
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보