0

I am trying to draw some intervals with PSTricks. I found some LaTeX code but I don't know how to edit it to get what I want.

I would like to draw the x-axis line with the interval in red but I don't want to have any graduation and I would like to write a and b under each extremity of my interval.

Here is the code that I have.

\documentclass[a4paper]{article}
\usepackage{pst-all}
\usepackage{pstricks-add}

\begin{document}
\psset{xunit=0.5cm, yunit=0.5cm, yAxis=false}   %scales the picture, removes the y-axis
\begin{pspicture}(-11,0)(11,0)  
\psaxes[Dx=5, subticks=5]{->}(0,0)(-11,0)(11,0) %creates axes
\psline[linewidth=3pt, linecolor=red]{[-]}(-2,0)(5,0)   %creates a thick, red line from -2 (closed) to 5 (closed)
\end{pspicture} 
\end{document}

Furthermore, is it possible to compile the document directly ? I mean, I use texmaker and with PST I have to compile with XeLatex then show the pdf, and I would like to show the pdf directly.

Thank you for helping !

2 Answers 2

0

Edited Version

Adaptations

  • inserted magic comment: %!TeX program = xelatex to tell the editor what it should use
  • replaced \psaxes by \psline{->} to just draw an arrow
  • added text a, b with \rput

Result

enter image description here

Code

%!TeX program = xelatex
\documentclass[a4paper]{article}
\usepackage{pst-all}
\usepackage{pstricks-add}

\begin{document}
\psset{xunit=0.5cm, yunit=0.5cm} %scales the picture
\begin{pspicture}(-11,0)(11,0)
    \psline{->}(-11,0)(11,0)
    \psline[linewidth=3pt, linecolor=red]{[-]}(-2,0)(5,0) %creates a thick, red line from -2 (closed) to 5 (closed)
    \rput(-2,-1){$a$}
    \rput(5,-1){$b$}
\end{pspicture}
\end{document}

Original Version

Adaptations

  • inserted magic comment: %!TeX program = xelatex to tell the editor what it should use
  • changed {[-]} to {-} at the \psline command to remove graduation
  • added text a, b with \rput

Result

enter image description here

Code

%!TeX program = xelatex
\documentclass[a4paper]{article}
\usepackage{pst-all}
\usepackage{pstricks-add}

\begin{document}
\psset{xunit=0.5cm, yunit=0.5cm, yAxis=false}   %scales the picture, removes the y-axis
\begin{pspicture}(-11,0)(11,0)  
    \psaxes[Dx=5, subticks=5]{->}(0,0)(-11,0)(11,0) %creates axes
    \psline[linewidth=3pt, linecolor=red]{-}(-2,0)(5,0)   %creates a thick, red line from -2 (closed) to 5 (closed)
    \rput(-2,.6){$a$}
    \rput(5,.6){$b$}
\end{pspicture}
\end{document}
2
  • Thank you a lot ! I am sorry I mistranslated, by graduation I meant the little lines and the numbers 0, 5, 10... In fact, I would like to draw an arrow with a generic interval.
    – Emilie
    Oct 29, 2022 at 16:18
  • @Emilie I made an edit to my answer. As these seem to be some basic pstricks commands, it might be useful to have a look at some starting guide or the introduction of the corresponding documentation.
    – dexteritas
    Oct 29, 2022 at 20:10
0

You can have the same result with two lines of Tikz code:

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
    \begin{tikzpicture}
        \draw[-latex] (-4.2,0) -- (7.2,0) node[below right]{$x$};
%       \foreach \i in {-4,...,7}
%       \draw[line width=.5,] (\i,.15)--(\i,-.15);
%       \foreach \i in {-4,-2,...,7}
%       \draw[line width=.5,] (\i,.15)--(\i,-.15) node[below] {\small $\i$};
        \draw[red,line width=4] (-2,0) node[above] {$a$}--(4,0) node[above] {$b$};
    \end{tikzpicture}
\end{document}

Output:

enter image description here

If You decomment the four central lines You have this output (with some scaling):

enter image description here

You must log in to answer this question.

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