2

I'm trying to draw a line from a point to a position 1cm above that point, but the following code doesn't seem to work. I would have thought that the yshift does the trick, but no line appears.

\documentclass[11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{pifont}
\usepackage{setspace}
\usepackage{needspace}
\usepackage[A4paper, portrait, margin=1in]{geometry}
\usepackage{qtree}
\usepackage{tipa}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{tikz-qtree-compat} %This seems to be necessary with covington
\usepackage{tikz} 
\usepackage{tikz-qtree}
\newsavebox{\partbox}
\usepackage{wrapfig}
\usepackage{multicol}
%\usepackage{makecell}
\usepackage{kotex}
\usepackage{covington}
\usepackage{fancybox}
\usepackage{makecell}
\usepackage[normalem]{ulem}

\newcommand\tikznode[3][]%
{\tikz[remember picture,baseline=(#2.base)]
    \node[minimum size=0pt,inner sep=0pt,#1](#2){#3};%
}
    
\begin{document}
        \begin{itemize}
        \item[] \tikznode{CP1}[\textsubscript{CP} John wonders \tikznode{CP2}[\textsubscript{CP} \tikznode{where}where Mary bought \tikznode{what}what ]] 
    \end{itemize}
    \begin{tikzpicture}[remember picture,overlay,rounded corners,>=stealth,shorten > =1pt,shorten <=1pt,thick]
        \draw[red,dashed,->] (what) -- +(0,+0.6) -| (CP1);
        \draw[double] ([yshift=1cm] where) -- (where);
    \end{tikzpicture}
\end{document}
2
  • 2
    Notice that the optional parameter to your tikznode macro should come first... And that you can't nest tikzpicture ever. – Rmano Apr 18 at 13:12
  • 1
    I suggest you look at tikzmark package... – Rmano Apr 18 at 13:14
4

With use of the tikzmark TikZ library:

\documentclass[11pt]{book}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}
%    \begin{itemize}
%\item[] 
    \tikzmarknode{CP1}{[}\textsubscript{CP} John wonders [\textsubscript{CP} 
    \tikzmarknode{where}{where} Mary bought 
    \tikzmarknode{what}{what}.
%\end{itemize}
\begin{tikzpicture}[remember picture,overlay,
                    rounded corners, >=stealth, 
                    shorten >=1pt,shorten <=1pt,
                    thick]
\draw[red,dashed,->] (what.north) -- +(0,+0.6) -| (CP1);
\draw[double] (where.north) ++ (0,1.2) -- (where);
    \end{tikzpicture}
\end{document}

enter image description here

Addendum: If in above MWE replace code line

\draw[double] (where.north) ++ (0,1.2) -- (where);

with

\draw[double] (where.north) ++ (0,1.1) -- + (0,-1);

then (according to my tase) the produced image is a wee bit nicer:

enter image description here

4

You are using your \tikznode incorrectly. It has two arguments, a node name and a text that you want to put into the node, plus an optional argument that can pass options to the node. Your usage is completely strange --- the first \tikznode for example has as arguments CP1 and [, the second one CP2 and [, and the third one where and w, which I suppose is not what you meant (I was wrong, there were no nested tikz calls!)

But the main problem because the [yshfit=1cm] does not work in your code is because the (where) is not a coordinate, but a node name. You have to pass a coordinate here:

\draw[double] ([yshift=1cm] where.north) -- (where);

notice that the second (where) is ok --- a plain (node) is substituted automatically by the border anchor --- that is, the point that connects the start of the line to the center of the node, situated on the border. I added a visible border to the node to show it (notice that it does not touch the borders for the shorten options), and put just the "where" in the node... but I have no idea about the semantic of this!

BTW: thanks to Markus G. to clean your example of unrelated packages.

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{graphicx}
\usepackage{tikz} 
\usetikzlibrary{calc}

\newcommand\tikznode[3][]%
{\tikz[remember picture,baseline=(#2.base)]
    \node[minimum size=0pt,inner sep=0pt,#1](#2){#3};%
}

\begin{document}
    \begin{itemize}
        \item[] \tikznode{CP1}{\textsubscript{CP}} John wonders
             \tikznode{CP2}{\textsubscript{CP}}
             \tikznode[draw, blue]{where}{where} 
             Mary bought \tikznode{what}{what}
    \end{itemize}
    \begin{tikzpicture}[remember picture,overlay,rounded corners,>=stealth,shorten > =1pt,shorten <=1pt,thick]
        \draw[red,dashed,->] (what) -- +(0,+0.6) -| (CP1);
        \draw[double] ([yshift=1cm] where.north) -- (where);
    \end{tikzpicture}
\end{document}

enter image description here

3

Maybe this solution using tikzlibrary calc is something that solves your problem:

\documentclass[11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{graphicx}
\usepackage{tikz} 
\usetikzlibrary{calc}

\newcommand\tikznode[3][]%
{\tikz[remember picture,baseline=(#2.base)]
    \node[minimum size=0pt,inner sep=0pt,#1](#2){#3};%
}

\begin{document}
    \begin{itemize}
        \item[] \tikznode{CP1}[\textsubscript{CP} John wonders \tikznode{CP2}[\textsubscript{CP} \tikznode{where}where Mary bought \tikznode{what}what ]] 
    \end{itemize}
    \begin{tikzpicture}[remember picture,overlay,rounded corners,>=stealth,shorten > =1pt,shorten <=1pt,thick]
        \draw[red,dashed,->] (what) -- +(0,+0.6) -| (CP1);
        \draw[double] ($(where)+(0,1cm)$) -- (where);
    \end{tikzpicture}
\end{document}
2
  • As you have already commented on this in the question, I hope you can appreciate that I didn't actually change this part of the original code. I simply focussed on the issue that was causing a problem. The code did compile without issues, but if you still feel there is an issue in terms of good practice, I invite you to give an answer of your own AND instead of simply pointing out that there is an error, I'd appreciate a constructive suggestion on how to aleviate it. – Markus G. Apr 18 at 17:31
  • sorry --- I didn't mean to be harsh; my apologies. I gave an answer here --- yes, the code compiles but the OP clearly used the \tikznode badly. The reason why their yshift did not work is explained in my answer. Using calc as you did is safer --- the node is equivalent to the center anchor in that case. – Rmano Apr 18 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.