How to shift a subtree of a tikz tree horizontally
Perhaps the best thing to do is place the work erschrekt
where you want it, to the left of ,die
. Since \node
is an abbreviation for \path node
you can add further material afterwards to draw more. Using the positioning
library you can place nodes relative to each other. Putting this code in the appropriate place tikz
will take care of moving the rest of the tree:
\documentclass[tikz]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{shapes, trees,calc,positioning}
\begin{document}
\begin{tikzpicture}[
font=\footnotesize,
edge from parent/.style={draw, edge from parent fork down},
frontier/.style={distance from root=250},
level distance=25,
phrase/.style={draw, ellipse},
function/.style={draw, rectangle}
]
\Tree
[.\node[phrase] {S};
[.\node[function] {SB}; Tim ]
[.\node[function] {HD}; wurde ]
[.\node[function] {OC};
[.\node[phrase] {VP};
[.\node[function] {SBP};
[.\node[phrase] {PP};
[.\node[function] {AC}; von ]
[.\node[function] {NK};
[.\node[phrase] {NP};
[.\node[function] {NK}; den ]
[.\node[function] {NK}; Hunden ]
[.\node[function] {RC};
[.\node[phrase] {S};
[.\node[function] {SB}; \node (die) {,die}
node[node distance=0cm,left=of die] (ert)
{\strut erschreckt}; ]
[.\node[function] {MO}; laut ]
[.\node[function] {HD}; bellten. ]
]
]
]
]
]
]
[.\node[function] (ers) {HD}; ]
]
]
];
\draw[red] (ers.south) |- ($(ers.south)!0.65!(ert.north)$)-| (ert.north);
\end{tikzpicture}
\end{document}
Note that I added \strut
to the new node to ensure it has a uniform depth. Other tikz
approaches would be to specify text height/depth
for your nodes generally.
Second Approach If you need adjust placement of paths and nodes even more, then I think it is actually easier to abandon the tree functions and draw the diagram essentially from scratch. The tree functions have a rather simplistic approach to placement of the child nodes. Here is one way to do this:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,calc,matrix}
\begin{document}
\begin{tikzpicture}[font=\footnotesize,anchor=base,
phrase/.style={draw, ellipse},
function/.style={draw, rectangle}]
\matrix (b) [matrix of nodes,column sep=1ex,text height=7pt,text depth=2pt] {
Tim
&wurde
&von
&den
&Hunden
&erschrekt
&,die
&laut
&bellten \\
};
\node[function] (19) at (b-1-1 |- 0,9) {SB};
\node[function] (29) at (b-1-2 |- 0,9) {HD};
\node[function] (35) at (b-1-3 |- 0,5) {AC};
\node[function] (43) at (b-1-4 |- 0,3) {NK};
\node[function] (53) at (b-1-5 |- 0,3) {NK};
\node[function] (67) at (b-1-6 |- 0,7) {HD};
\node[function] (71) at (b-1-7 |- 0,1) {SB};
\node[function] (81) at (b-1-8 |- 0,1) {MO};
\node[function] (91) at (b-1-9 |- 0,1) {HD};
\node[phrase] (S2) at ($(71.base)!0.5!(91.base) + (0,1)$) {S};
\node[function] (R3) at ($(S2.base) + (0,1)$) {RC};
\node[phrase] (N4) at ($(43.base)!0.3!(R3.base) + (0,1)$) {NP};
\node[function] (N5) at ($(N4.base) + (0,1)$) {NK};
\node[phrase] (P6) at ($(35.base)!0.5!(N5.base) + (0,1)$) {PP};
\node[function] (S7) at ($(P6.base) + (0,1)$) {SBP};
\node[phrase] (V8) at ($(S7.base)!0.5!(67.base) + (0,1)$) {VP};
\node[function] (O9) at ($(V8.base) + (0,1)$) {OC};
\node[phrase] (S10) at ($(19.base)!0.5!(O9.base) + (0,1)$) {S};
\draw (b-1-1) -- (19) -- +(0,0.5) -| (S10);
\draw (b-1-2) -- (29) -- +(0,0.5);
\draw (b-1-3) -- (35) -- +(0,0.5) -| (P6) -- (S7) -- +(0,0.5) -| (V8)
-- (O9) -- +(0,0.5) -| (S10);
\draw (b-1-4) -- (43) -- +(0,0.5) -| (N4) -- (N5) -- +(0,0.5) -|
(P6);
\draw (b-1-5) -- (53) -- +(0,0.5);
\draw (b-1-7) -- (71) -- +(0,0.5) -| (S2) -- (R3) -- +(0,0.5) -| (N4);
\draw[white,double=black,line width=3pt,double distance=0.4pt,
shorten >=0.2pt] (b-1-6) -- (67); \draw (67) -- +(0,0.5) -| (V8);
\draw (b-1-8) -- (81) -- +(0,0.5);
\draw (b-1-9) -- (91) -- +(0,0.5) -| (S2);
\end{tikzpicture}
\end{document}
I have used \matrix
to place the words evenly, and adjusted the column separation at avoid overlaps further up in the diagram. Other nodes are then place relative to the matrix entries, referring to base points of nodes for consistency.
The calc
library allows us to use expressions such as ($(A)!0.5!(B)$)
for the point half way between (A)
and (B)
; the syntax (A |- B)
(which does not require calc
) finds the point whose x-coordinate is that of (A)
and y-coordinate of that of (B)
.
I have placed nodes vertically on levels correspanding to (0,n)
with n
a whole number and labelled them with names that end in the level number; the vertical line out of a node then goes to height (0,n+0.5)
before being joined to a horizontal bar; these horizontal bars need only been drawn from the nodes at their left and right ends. Finally, the crossing line has be drawn "doubled" with a wide white background creating a hole in the horizontal line it crosses. I have also shortened it a bit so that it does not overlap the border of the nodes. 0.4pt
has been used as the standard reference line width in these cases.