# Text appears after "pspicture" section even when it's inserted above it. How to preserve order?

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:

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:

• Welcome to TeX SX! Inserting a blank line between the heading and the environment should be enough. 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 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. 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. Nov 20 '17 at 19:18

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}


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}

• showgrid is an amazing tip thank you! Now I can clearly see what space the picture is occupying. Nov 21 '17 at 11:46