Graphics, Figures & TablesPSTricks | Code Generalization

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | Code Generalization

Post by svend_tveskaeg »

Hi all.

Consider the following MWE:

Code: Select all

\documentclass[danish]{article}
\usepackage{babel}
\usepackage{auto-pst-pdf,pstricks-add}

\begin{document}

\begin{pspicture}(0,-6)(15,2)
\psset{unit=0.75cm}
 \psaxes[
   xLabels={,Lake Placid,,Sarajevo,,Calgary,,Albertville,Lillehammer,,Nagano,,Salt Lake City,,Torino,},
   xLabelsRot=90,
   yAxis=false
 ]{->}(15,0)
 \multido{\iA=1+2,\iB=8+2,\iC=1984+4,\iD=1994+4}{4}{%
   \rput(\iA,1){\psrotate(0.55,0.05){90}{$\iC$}}
   \rput(\iB,1){\psrotate(0.55,0.05){90}{$\iD$}}
 }
\end{pspicture}

\end{document}
(It should be compiled using pdflatex -shell-escape <filename>.tex.)

The above example is exactly what I want but I it will get somewhat more complicated if the number of olympics on every side the periode where it switched from

year x (mod 4) = 0

to

year x (mod 4) = 2

is not the same. Is there a way to generalise the code in the above example in order to get around this?

Thank you in advance!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

PSTricks | Code Generalization

Post by CrazyHorse »

svend_tveskaeg wrote:The above example is exactly what I want but I it will get somewhat more complicated if the number of olympics on every side the periode where it switched from

year x (mod 4) = 0

to

year x (mod 4) = 2

is not the same. Is there a way to generalise the code in the above example in order to get around this?
A too complicated example.

Code: Select all

\documentclass{article}
\usepackage{pstricks-add}

\def\RPut(#1)#2{%
  \rput[r]{90}(!#1 1984 sub 2 div 0){#2\quad}%
  \rput[l]{90}(!#1 1984 sub 2 div 0){\quad#1}%
}

\begin{document}
  \begin{pspicture}(0,-6)(15,2)
    \psset{unit=0.75cm}
    \psaxes[labels=none,Dx=2,dx=1,yAxis=false,Ox=1984]{->}(15,0)
    \RPut(1984){Lake Placid}
    \RPut(1988){Sarajewo}
  \end{pspicture}
\end{document}
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: PSTricks | Code Generalization

Post by svend_tveskaeg »

Great!

Thank you very much.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply