3

I would like to place a multiline text (w/o a priori knowledge of the number of lines) with zero depth. When n = 1 the solution is easy (text depth = 0pt), but with n > 1 this does not work properly. What do I have to do to achieve the wanted effect?

In the second part of the example the baseline of the text is identical with the line drawn. In the third example I would like to get the same, but here are the descenders on the line drawn.

\documentclass{minimal}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[inner sep=0pt]
 \draw (0,0) -- (5,0);
 \node[text width=5cm,above] at (2.5,0)
    {Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Lorem ipsum dolor sit amet, };

 \begin{scope}[yshift=3cm]
    \draw (0,0) -- (5,0);
    \node[text width=5cm,text depth=0pt,above] at (2.5,0)
       {Lorem ipsum dolor sit amet, };
 \end{scope}

 \begin{scope}[yshift=6cm]
    \draw (0,0) -- (5,0);
    \node[text width=5cm,text depth=0pt,above] at (2.5,0)
       {Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Lorem ipsum dolor sit amet, };
 \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

Jürgen
  • 2,160
  • Welcome to TX.SX! I've include the result of your code. From it I don't understand the question, could you better explain what you want to obtain? By the way, take a look at http://tex.stackexchange.com/questions/42114/why-should-the-minimal-class-be-avoided – Ignasi Dec 11 '15 at 07:58
  • 1
    Can you manually draw it and upload what you want exactly? so that one can understand the question. – David Dec 11 '15 at 08:42
  • @ Ignasi: Thanks for adding the picture. @David: I have added another sentence to hopefully clarify my aim. – Jürgen Dec 11 '15 at 09:07

2 Answers2

5

Is this what you want?

enter image description here

If yes, the solution is a node with inner sep=-depth("p").

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[inner sep=0pt]
 \draw (0,0) -- (5,0);
 \node[text width=5cm,above, inner sep=-depth("p")] at (2.5,0)
    {Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Lorem ipsum dolor sit amet, };
\end{tikzpicture}
\end{document}
Ignasi
  • 136,588
  • Yes, this is (nearly) exactly what I want. Many thanks for that idea! It is even better for me to set above=-depth("p") (with inner sep I change the distance in all four directions). The only small problem is, that this also causes a shift when there is no descender in the text; but if I add a \vphantom{q} ... – Jürgen Dec 11 '15 at 10:42
  • 1
    @Jürgen Glad to help you. Yes inner sep changes inner margin, but you can also use inner xsep or inner ysep which affect only to inner horizontal o vertical distance between node text and border. – Ignasi Dec 11 '15 at 11:18
  • Ok, good to know. But I think and hope that the approach with above will do the trick. – Jürgen Dec 11 '15 at 11:59
2

Unfortunately, when textwidth is used the minipage installed before the node contents uses the [t] option and this is not customizable. However, this customization can be more-or-less successfully achieved using the execute at begin node and execute at end node keys:

\documentclass[tikz,border=5]{standalone}
\tikzset{minipage/.style 2 args={%
  execute at begin node=\begin{minipage}[#1]{#2}\raggedright,
  execute at end node=\end{minipage},
  anchor=base
}}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (5,0);
\node[minipage={b}{5cm}] at (2.5,0) {Lorem ipsum dolor sit amet};

\tikzset{shift=(270:2)}
\draw (0,0) -- (5,0);
\node[minipage={b}{5cm}] at (2.5,0) {Lorem ipsum dolor sit amet, 
  consectetuer adipiscing elit};

\tikzset{shift=(270:2)}
\draw (0,0) -- (5,0);
\node[minipage={b}{5cm}] at (2.5,0) {Lorem ipsum dolor sit amet, 
  consectetuer adipiscing elit. Lorem ipsum dolor sit amet};
\end{tikzpicture}
\end{document}

enter image description here

Mark Wibrow
  • 70,437
  • Thanks, Mark, for this canonic solution. I must admit that the other solution is, at least for me, a bit simpler to use. But I will have a closer look at the execute at begin/end node options. – Jürgen Dec 11 '15 at 12:40