2

I want the heading "SCALENE TRIANGLE" to appear above the diagram. But that is not what happens, even if the text is inserted above the section.

Code:

\documentclass{article}
\usepackage{pstricks}
\usepackage{pst-node}

\usepackage{FiraMono}
\usepackage[T1]{fontenc}


\begin{document}
    \section{Triangles}
    \subsection{Scalene Triangle}
    \newline
    \begin{pspicture}(0,0)
        \pspolygon(1,1)(3,4)(9,1)   %triangle
        \psline[linestyle=dashed](3,4)(3,1) %height
        \pspolygon(3,1)(3,1.2)(3.2,1.2)(3.2,1)  %right angle
        \uput{0.1}[180](1,1){A}
        \uput{0.1}[90](3,4){B}
        \uput{0.1}[0](9,1){C}
        \uput{0.2}[0](6,2.5){a}
        \uput{0.2}[270](5,1){b}
        \uput{0.2}[180](2,2.5){c}
        \uput{0.2}[0](3,2.5){h}
    \end{pspicture} 
    $$area = \sqrt{s(s-a)(s-b)(s-c)},\quad s = \frac{(a+b+c)}{2}$$
    \subsection{Right Angled Triangle}
\end{document}

Output:

enter image description here

OLD CODE PLEASE IGNORE

My Code:

\documentclass{article}
\usepackage{pstricks}
\usepackage{pst-node}

\usepackage{FiraMono}
\usepackage[T1]{fontenc}


\begin{document}
    SCALENE TRIANGLE
\begin{pspicture}(0,0)
    \pspolygon(1,1)(3,4)(9,1)   %triangle
    \psline[linestyle=dashed](3,4)(3,1) %height
    \pspolygon(3,1)(3,1.2)(3.2,1.2)(3.2,1)  %right angle
    \uput{0.1}[180](1,1){A}
    \uput{0.1}[90](3,4){B}
    \uput{0.1}[0](9,1){C}
    \uput{0.2}[0](6,2.5){a}
    \uput{0.2}[270](5,1){b}
    \uput{0.2}[180](2,2.5){c}
    \uput{0.2}[0](3,2.5){h}
\end{pspicture}
    $$area = \sqrt{s(s-a)(s-b)(s-c)},\quad s = \frac{(a+b+c)}{2}$$
\end{document}

Output:

output

6
  • 1
    Welcome to TeX SX! Inserting a blank line between the heading and the environment should be enough.
    – Bernard
    Nov 20 '17 at 19:01
  • you have specified (0,0) so the pspicture takes up no space, and you have used positive coordinates so it over-prints anything above it. Nov 20 '17 at 19:08
  • @Bernard Inserting \\newline after section or subsection yields this error: There's no line here to end. \subsection{Scalene Triangle}\\n
    – Finch
    Nov 20 '17 at 19:13
  • @DavidCarlisle \begin{pspicture}(0,5) solved it. But is there a better way to do it? I am a n00b.
    – Finch
    Nov 20 '17 at 19:15
  • I mentioned a blank line, that's all, but there was no section in your initial post. You should give the dimensions of the pspicture. Also, don't use $$ ... $$ for displayed equation: this is plain TeX syntax, and it produces bad spacing with LateX. Use \[ ... \]instead.
    – Bernard
    Nov 20 '17 at 19:18
1

I propose a shorter code with pst-eucl, which is dedicated to plane geometry. No coordinates calculations are required – only the coordinates of A, B,C are used:

\documentclass[svgnames]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pst-node, pst-eucl}
\usepackage{amsmath}
\usepackage{FiraMono}

\begin{document}

\section{Triangles}
\subsection{Scalene Triangle}
\begin{center}
    \begin{pspicture*}(0.5,0.5)(9.5,4.5)
        \psset{PointSymbol = none, RightAngleSize = 0.2, linecolor = NavyBlue}
        \pstTriangle[PosAngle = {180,90,0}](1,1){A}(3,4){B}(9,1){C} %triangle
        \pstProjection[CodeFig, linewidth = 0.4pt, CodeFigColor = Tomato]{A}{C}{B}[H]\naput{$ h $}
        \psset{linestyle = none, labelsep = 2pt}
        \ncline{B}{C}\naput{$a$}
        \ncline{C}{A}\naput{$b$}
        \ncline{A}{B}\naput{$c$}
    \end{pspicture*}
\end{center}
\[ \text{area} = √{s(s-a)(s-b)(s-c)},\quad s = \frac{a+b+c}{2} \]

\end{document} 

enter image description here

2

Use the optional argument [showgrid]. Then you'll see what rectangle you have reserved for the image. If everything is fine, set showgrid=false

\documentclass{article}
\usepackage{pstricks}
\usepackage{pst-node}
\usepackage{FiraMono}
\usepackage[T1]{fontenc}

\begin{document}
    \section{Triangles}
    \subsection{Scalene Triangle}

    \begin{pspicture}[showgrid](10,5)
    \pspolygon(1,1)(3,4)(9,1)   %triangle
    \psline[linestyle=dashed](3,4)(3,1) %height
    \pspolygon(3,1)(3,1.2)(3.2,1.2)(3.2,1)  %right angle
    \uput{0.1}[180](1,1){A}
    \uput{0.1}[90](3,4){B}
    \uput{0.1}[0](9,1){C}
    \uput{0.2}[0](6,2.5){a}
    \uput{0.2}[270](5,1){b}
    \uput{0.2}[180](2,2.5){c}
    \uput{0.2}[0](3,2.5){h}
    \end{pspicture} 

    \[\textrm{area} = \sqrt{s(s-a)(s-b)(s-c)},\quad s = \frac{(a+b+c)}{2}\]

    \subsection{Right Angled Triangle}
\end{document}
1
  • showgrid is an amazing tip thank you! Now I can clearly see what space the picture is occupying.
    – Finch
    Nov 21 '17 at 11:46

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.