15

I am experimenting with Tikz to include graphics in my LaTeX documents. I have made a few 2D and 3D diagrams. One of the diagrams contains a 3D pyramid. I want to place text on the front and side of the pyramid. I managed to place text on the front. Placing text on the side however is a problem for me because it is not in perspective and therefore ruining the 3D experience.

I want the text on the side to be rotated in such a way that it appears to be in the same pane as the side. I could try to rotate the text but then positioning is cumbersome. There must be a better way to do this? Somehow write text on the z-axis instead of in the x/y pane.

I managed to produce something to illustrate what i had in mind. There should be a better way to achieve this. The text is obviously not 3D aware and therefore not in perspective. Also the text is not aware of the figure and with larger texts it runs outside the boundaries of the illustration as it is not contained by the edges.

Any suggestions would be really appreciated. Thank you in advance!

\begin{tikzpicture}[scale=0.5]
\example of my pyramid:
\path   coordinate (0) at (0,0,0)
    % The base layer
    coordinate (A) at (-9,0,9)
    coordinate (B) at (9,0,9)
    % The middle layer
    coordinate (C) at (-6,4,6)
    coordinate (D) at (6,4,6)
    % The top layer
    coordinate (E) at (-3.75,7,3.75)
    coordinate (F) at (3.75,7,3.75)
    coordinate (G) at (0,12,0)

    % 3d effect
    % The base layer
    coordinate (AA) at (-9,0,-9)
    coordinate (BB) at (9,0,-9)
    % The middle layer
    coordinate (CC) at (-6,4,-6)
    coordinate (DD) at (6,4,-6)
    % The top layer
    coordinate (EE) at (-3.75,7,-3.75)
    coordinate (FF) at (3.75,7,-3.75);

    % Draw lines between points
    \draw (A) -- (B) -- (BB);
    \draw (C) -- (D) -- (DD);
    \draw (E) -- (F) -- (FF);
    \draw (A) -- (G) -- (B);
    \draw (G) -- (BB);

    % Text added to node positioned at center of segment.
    \node at (0,2,7.5) {Base of the pyramid};
    \node at (0,5.5,4.875) {Middle section};        
    \node at (0,9,1.875) {Top of the pyramid};
    % Rotated text added to node positioned at center of segment.
    \node [rotate=45] at (7.5,2,0) {Base};
    \node [rotate=45] at (4.875,5,0) {Middle};
    \node [rotate=45] at (1.875,9,0) {Top};

\end{tikzpicture}
2
  • 1
    You need to use xslant and yslant but without some code it's difficult to give a good answer. Commented Jul 3, 2012 at 8:33
  • Dear Altermundus, thank you very much for your contribution. I have added a small piece of example code. You might be right with xslant and yslant but that only works when skewing a 2D plane? I used 3D coordinates for the pyramid. I am probably approaching this wrong.
    – Pharao
    Commented Jul 3, 2012 at 11:53

2 Answers 2

12

With \usetikzlibrary{calc}

\path ($(B)!.5!(D)$) -- node[sloped,xslant=.2] {Base} ($(BB)!.5!(DD)$);

gives

enter image description here

With xslant=.5

enter image description here

4
  • Dear Altermundus, thank you very much for your contribution. It was really helpful!
    – Pharao
    Commented Jul 4, 2012 at 12:48
  • Dear Altermundus, thank you very much for your contribution. It was really helpful! The text on the side looks really nice. Actually it looks better then the front text. Therefor I wonder how you placed the text on the front side of thy pyramid? On the top section you have a line break. Did you use a manual break of does the text wrap automatically? I can only use small words now because larger texts would not fit in the pyramid sections. My sentences are on a single line and are not contained by their respective sections but run outside the borders of the sections.
    – Pharao
    Commented Jul 4, 2012 at 12:54
  • I found the solution to my linebreak problem. I forgot to add the [alignment=center] option. Without alignment the linebreak has no effect. Thank you so much for the help. I am very grateful!
    – Pharao
    Commented Jul 4, 2012 at 13:29
  • @Pharao You are right, you need [alignment=center] and you can add text width. You can also use [alignment=center] with \\. Commented Jul 4, 2012 at 16:29
5

run with xelatex or latex->dvips->ps2pdf

\documentclass{article}
\usepackage{pst-solides3d}
\begin{document}

\psset{Decran=30,viewpoint=30 -15 10 rtp2xyz,solidmemory}
\begin{pspicture}(-4,-1)(4,4)
\psSolid[object=new,sommets=0 -3 0 %% 0
                            -3 0 0 %% 1
                             0 3 0 %% 2
                             3 0 0 %% 3
                             0 0 5, %% 4
  faces={[3 2 1 0][3 4 0 ][4 3 2][4 2 1][4 1 0]},
%   numfaces=all,num=all,
   intersectiontype=0,
   intersectionplan={[0 0 1 -2] [0 0 1 -3.5]},
   intersectionlinewidth=1 1,
   intersectioncolor=(bleu) (rouge),
   fillcolor=green!20!white,linecolor=green!60!black,
   name=P,action=draw*]
\psSolid[object=plan,action=none,definition=solidface,args=P 1,name=P1]
\psSolid[object=plan,action=none,definition=solidface,args=P 2,name=P2]
\psProjection[object=texte,phi=-139,pos=dc,text=Base of the pyramid,plan=P2]
\psProjection[object=texte,phi=-40,pos=uc,text=Top,plan=P1](1.6,1.8)
\psProjection[object=texte,phi=-40,pos=dc,fontsize=12,text=Base of the pyramid,plan=P1](-0.8,-0.8)
\end{pspicture}
\end{document}​

enter image description here

You must log in to answer this question.

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