7

I want to create a sort of text box, path you maybe want to call it, using TikZ, which has the shape of a triangle. I then want the text follows the hypotenuse of the triangle.

    /
   / The text follows the
  / the Path of the
 / hypotenuse 
/    

How do I make this possible, using TikZ? At the moment I'm just defining three nodes and using xshift I align every line with the the hypotenuse.

UPDATE

I had to be a bit more clear about defining the text, but the text should be defined in one instance so \text{The text follows the \\ the path of the \\ hypotenuse}

This just came up with me but the text in the 'textbox' should also have justification. So the image would maybe look more like...

    /                  |
   / This is some text |
  / this    is    also | <-- line is justified
 / hypotenuse          |
/                      |
1

1 Answer 1

13

If the text is not long, then, you can get away without defining a paragraph shape via decoration.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}

\begin{tikzpicture}[mystyle/.style args={#1 at #2}{
            decoration={
                  markings,
                  mark=at position #2 with {
                      \node[anchor=west,xshift=5pt]{#1};}
                  },
            postaction={decorate}
            }
    ]
    \draw[%
          mystyle=Some Text  at 0.2,
          mystyle={some text with \textit{at} in it} at 0.4
         ] (0,0) -- (3,3);
\end{tikzpicture}

\end{document}

enter image description here

EDIT If the text is not short and requires some effort with the above method then we have to define a paragraph shape. I defined a simple shape and put the resulting paragraph into a node on the line by anchoring it from its left side. Here is the result:

\documentclass{article}
\usepackage{tikz,shapepar}
\newcommand{\myparshape}{
{5}
{0}b{5}\\ 
{0}t{5}{5}\\ 
{5}t{0}{10}\\ 
{5}e{0}
}

\begin{document}
\begin{tikzpicture}

  \draw (0,0) -- (5,5);
  \node[anchor=west,xshift=-1cm] at (2.5,2.5) {\begin{minipage}{0.5\textwidth}
        \Shapepar{\myparshape} Some ridiculous text to fill 
        up this space. I could have used lipsum or kantlipsum packages to generate 
        this but I thought those would give me longer paragraphs then I would need. 
        Then again I wouldn't worry too much.
        \end{minipage}
    };

\end{tikzpicture}
\end{document}

enter image description here

3
  • Hmmm not quiet the solution I was looking for because I now implemented it in a similar fashion. Maybe I had to be a bit more clear about the text, but I want the text to be able to be defined in a single instance. Let me clarify that -- The code has to output the same way as your picture but going to a newline should just be easy as using \\ \draw[mystyle={Some text with \textit{at} in it \\ Some Text}. It would also be nice if the text in the textbox would have full justification in it. I will explain this in my question.
    – WG-
    Jun 14, 2012 at 10:58
  • @Wouter Is it better now?
    – percusse
    Jun 14, 2012 at 12:11
  • awesome! That was exactly what I was looking for! I will try to implement your result now :-)
    – WG-
    Jun 14, 2012 at 12:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .