TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to draw a picture of an initial segment of the cumulative hierarchy of set theory. I generated the following MWE:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[thick, scale=2.0]
        \draw[ultra thick] (0,0) -- (1,2);
        \draw[ultra thick] (0,0) -- (-1,2);
        \foreach \y in {.3, .6,...,2}
        \draw (-1,\y) -- (1,\y);
\end{tikzpicture}
\end{document}

Which produces the following picture:

enter image description here

The vertical spacing of the horizontal lines is correct, but how do I shorten them so that they end at the lines of the V rather than stretching beyond them?

EDIT: The accepted answer perfectly answers the question asked. The answer from cfr, however, provides a more general solution and so may be preferred.

share|improve this question
up vote 7 down vote accepted

The solution is solving two linear equations.

\documentclass[border=6pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[thick, scale=2.0, auto]
        \draw[ultra thick] (0,0) -- (1,2);
        \draw[ultra thick] (0,0) -- (-1,2);
        \foreach \y in {.3, .6,...,2}
        \draw (-1/2*\y,\y) -- (1/2*\y,\y);
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer

This doesn't, strictly speaking, answer the question because it does not work within the loop but acts as a constraint on the loop. However, the effect is the same.

You can use \clip to clip the lines to the required area and not worry about specifying how long they should be. Although it is relatively simple to figure out how long they should be in this case, that is not always so. Hence, clipping is a generally useful technique which can be applied in more complex cases.

\documentclass[margin=10pt,tikz,multi]{standalone}
\begin{document}
\begin{tikzpicture}[thick, scale=2.0]
  \draw[ultra thick] (-1,2) -- (0,0) -- (1,2);
  \clip (-1,2) -- (0,0) -- (1,2) -- cycle;
  \foreach \y in {.3, .6,...,2} \draw (-1,\y) -- (1,\y);
\end{tikzpicture}
\end{document}

clipped lines

share|improve this answer
1  
Thanks, this answers the question I should have asked :) – Dennis Jan 17 at 3:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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