Take the 2-minute tour ×
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.

I have tried to create a PSTricks figure based on only a few parameters but I have a problem.

Code

\documentclass{article}

\usepackage{auto-pst-pdf,pstricks-add}
\usepackage{expl3}

\ExplSyntaxOn
  \cs_new_eq:NN
    \calc
  \fp_eval:n
\ExplSyntaxOff

% Parameters
\def\radius{1.5 }
\def\doublelayers{2}
\def\columns{2}

\begin{document}

\begin{figure}[htbp]
\def\diameter{\calc{2*\radius}}
\def\distance{\calc{2*3^(1/2)*\radius}}
\def\width{\calc{(2*\columns+1)*\radius}}
\def\height{\calc{(2+3^(1/2)*(\doublelayers-1))*\radius}}
 \centering
  \begin{pspicture}(\width,\height)
   \rput(\radius,\radius){
     \multido{\rC=0+\diameter}{\columns}{
       \multido{\rD=0+\distance}{\doublelayers}{
         \psdot(\rC,\rD)
         \pscircle(\rC,\rD){\radius}
       }
     }
   }
   \rput(!2 \radius mul 1 3 sqrt add \radius mul){
     \multido{\rE=0+\diameter}{\columns}{
       \multido{\rF=0+\distance}{\doublelayers}{
         \psdot(\rE,\rF)
         \pscircle(\rE,\rF){\radius}
       }
     }
   }
  \end{pspicture}
\end{figure}

\end{document}

The document should be compiled using

pdflatex -shell-escape <filename>.tex

Question

How do I change the code from using \doublelayers to using single layers? The point is that if there are 2n layers, there should be should be drawn n layers to the far-left and n layers indented by an amount of \radius; if there are 2n-1 layers, there should be should be drawn n layers to the left and n-1 layers indented.

Example: If I have three layers, the code should draw two rows of circles beginning at the left of the figure and one row of circles in between, indented.

The following picture shows 2 double layers. With 3 single layers, the top row shouldn't be there.

enter image description here

Update

I have crosspost this to the LaTeX Community since this post seems to be `dead', so I try there.

share|improve this question
    
I've posted one possible solution. I'm a bit unclear why this was difficult for you. I suspect that I am probably not understanding what you're really asking for. I think you'll get more bites if you post your own attempt (even if it doesn't work), at accomplishing what you want. –  A.Ellett Feb 26 '13 at 5:58
    
See the comment to your answer. –  Svend Tveskæg Feb 26 '13 at 6:08

1 Answer 1

I'm really foggy on what you're asking for.

Is this what you're asking for?

enter image description here

If the above image is the case, there's a very easy solution:

\documentclass{article}

\usepackage{auto-pst-pdf,pstricks-add}
\usepackage{expl3}

\ExplSyntaxOn
  \cs_new_eq:NN
    \calc
  \fp_eval:n
\ExplSyntaxOff

% Parameters
\def\radius{1.5 }
\def\doublelayers{3}
\def\columns{2}
\pagestyle{empty}
\begin{document}

\begin{figure}[htbp]
\def\diameter{\calc{2*\radius}}
\def\distance{\calc{2*\radius}}%{\calc{2*3^(1/2)*\radius}}
\def\width{\calc{(2*\columns+1)*\radius}}
\def\height{\calc{(2+3^(1/2)*(\doublelayers-1))*\radius}}
 \centering
  \begin{pspicture}(\width,\height)
   \rput(\radius,\radius){
     \multido{\rC=0+\diameter}{\columns}{
       \multido{\rD=0+\distance}{\doublelayers}{
         \psdot(\rC,\rD)
         \pscircle(\rC,\rD){\radius}
       }
     }
   }
%   \rput(!2 \radius mul 1 3 sqrt add \radius mul){
%     \multido{\rE=0+\diameter}{\columns}{
%       \multido{\rF=0+\distance}{\doublelayers}{
%         \psdot(\rE,\rF)
%         \pscircle(\rE,\rF){\radius}
%       }
%     }
%   }
  \end{pspicture}
\end{figure}

\end{document}

Are you asking for something more or less dynamic, so that you can specify how ever many layers you want?

OK. I think I understand a bit better what you want. Here's a MWE. It could use some improving, but I'm tired right now. I'll come back to it tomorrow.

\documentclass{article}
\usepackage{xcolor}
\usepackage{auto-pst-pdf,pstricks-add}
\usepackage{expl3}

\ExplSyntaxOn
  \cs_new_eq:NN
    \calc
  \fp_eval:n
\ExplSyntaxOff

% Parameters
\def\radius{0.75 }
\def\doublelayers{5}
\newcounter{bluedoublelayers}
\ifodd\doublelayers\relax%
    \setcounter{bluedoublelayers}{\number\numexpr\doublelayers-1\relax}%
    \else%
    \setcounter{bluedoublelayers}{\doublelayers}%
    \fi
\def\columns{2}
\pagestyle{empty}
\begin{document}

\begin{figure}[htbp]
\def\diameter{\calc{2*\radius}}
\def\distance{\calc{2*3^(1/2)*\radius}}
\def\width{\calc{(2*\columns+1)*\radius}}
\def\height{\calc{(2+3^(1/2)*(\doublelayers-1))*\radius}}
 \centering
  \begin{pspicture}(\width,\height)
   \rput(\radius,\radius){
     \multido{\rC=0+\diameter}{\columns}{
       \multido{\rD=0+\distance}{\doublelayers}{
         \psdot(\rC,\rD)
         \pscircle(\rC,\rD){\radius}
       }
     }
   }
   \rput(!2 \radius mul 1 3 sqrt add \radius mul){
     \psset{linecolor=blue}
     \multido{\rE=0+\diameter}{\columns}{
       \multido{\rF=0+\distance}{\thebluedoublelayers}{
                \psdot(\rE,\rF)
                \pscircle(\rE,\rF){\radius}
       }
     }
   }
  \end{pspicture}
\end{figure}

\end{document}

When you set doublelayers to 2, the result is:

enter image description here

When you set doublelayers to 3, the result is:

enter image description here

share|improve this answer
    
This is exactly what I am asking for. :) I am not used to begin abel to attach pictures but I have done that now. –  Svend Tveskæg Feb 26 '13 at 6:06
    
This looks promising, @a.ellett! I would like to create single layers instead of doubles so that I can draw, say, three columns and three rows by setting \def\rows{3} (there \doublelayers is replaced by \rows) and \def\columns{3}. –  Svend Tveskæg Feb 26 '13 at 14:20
    
Have you (or anyone else) come up with an idea of how to do what I would like to accomplish? –  Svend Tveskæg Mar 3 '13 at 8:19

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.