3

I wish to label a diagonal line in Tikz so that the text runs diagonally yet is upright. My use case is just a row of small 1's for a triangular matrix, but something flexible is preferred. Something like just drawing a dashed line, but instead of dashes or dots its small 1's/numbers/letters that are upright.

I would think that this has been done before, but my google kungfu didn't manage it.

  • 2
    Welcome to TeX SE! Please add a small, compilable document which can form the basis of a solution. (A Minimum Working Example or MWE.) This makes it a lot easier (and more fun) for people to help you! – cfr Oct 27 '14 at 19:38
4

Do you mean something like this:

enter image description here

Code:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \draw [-latex, blue, ultra thick] (0,0) -- (20:2.5cm);
    \foreach \x in {1,...,10} { 
        \node  [above] at (20:0.2*\x cm) {1};
    }
\end{tikzpicture}
\end{document}
2

I found I needed more control than Peter Grill's answer (which did what I asked), so I'm just leaving this here for others. It requires the decorations tikz option.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.marking}

\begin{document}
    \begin{tikzpicture}
        \node (a) at (0,0) {A};
        \node (b) at (2,2) {B};

        \path [postaction = {decorate, decoration = 
            {markings, mark = between positions 0.0 and 1 step 0.2 with 
                {\node[font=\tiny]{1};}}}] (a) -- (b)
    \end{tikzpicture}
\end{document}

diagonal 1's from (a) to (b)

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.