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 wish to draw the cross diamond, however the line of the cross is inside the diamond, like described in the picture.

enter image description here

However, I tried the code below, the result is

\node[draw, diamond, below=of aux] (cross diamond) {};
\draw (cross diamond.north) -- (cross diamond.south)
      (cross diamond.west) -- (cross diamond.east);

enter image description here

share|improve this question
1  
While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. This is especially important for tikz as there are numerous libraries. –  Peter Grill Feb 15 '13 at 1:19
    
Similar to tex.stackexchange.com/q/44073/1410 –  morbusg Feb 15 '13 at 14:46
    
@morbusg Yes it appears its a duplicate bu the answers are different and show different techniques. –  Marc van Dongen Feb 15 '13 at 21:10
    
@Marc: Yeah I merely meant to get it listed on the right under “Linked”. –  morbusg Feb 15 '13 at 21:41

3 Answers 3

up vote 15 down vote accepted

You can use [shift=<length>] option (shown in red), or with tikz's calc library you can perform coordinate calculations (shown in blue). Also, if you desire rounded corners as per your original image you can add the rounded corners=<length> as I have done for the red version:

enter image description here

Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,shapes,positioning}
\newcommand*{\Shift}{0.6ex}%
\begin{document}
\begin{tikzpicture}[thick,red]
\node[draw, diamond, rounded corners=1.5pt] (cross diamond) {};
\draw  ([yshift=-\Shift]cross diamond.north)
    -- ([yshift=+\Shift]cross diamond.south)
       ([xshift=+\Shift]cross diamond.west) 
    -- ([xshift=-\Shift]cross diamond.east);
\end{tikzpicture}
\hspace*{1.0cm}
\begin{tikzpicture}[thick,blue]
\node[draw, diamond] (cross diamond) {};
\draw  ($(cross diamond.north) - (0,\Shift)$)
    -- ($(cross diamond.south) + (0,\Shift)$)
       ($(cross diamond.west)  + (\Shift,0)$)
    -- ($(cross diamond.east)  - (\Shift,0)$);
\end{tikzpicture}
\end{document}
share|improve this answer
    
thanks, got it:) –  sweetyBaby Feb 15 '13 at 2:00

We could also define a shape. Most of the work is already done by the diamond shape, so with a brief hack (one day I will post an answer without hacking), we can use something like this:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\pgfkeys{/pgf/crossed diamond shorten/.initial=0pt}

\makeatletter
\pgfdeclareshape{crossed diamond}{
    \inheritsavedanchors[from=diamond]
    \inheritanchorborder[from=diamond]
    \inheritanchor[from=diamond]{center}
    \inheritanchor[from=diamond]{text}
    \inheritanchor[from=diamond]{base}
    \inheritanchor[from=diamond]{base west}
    \inheritanchor[from=diamond]{base east}
    \inheritanchor[from=diamond]{mid}
    \inheritanchor[from=diamond]{mid west}
    \inheritanchor[from=diamond]{mid east}
    \inheritanchor[from=diamond]{north}
    \inheritanchor[from=diamond]{south}
    \inheritanchor[from=diamond]{west}
    \inheritanchor[from=diamond]{east}
    \inheritanchor[from=diamond]{north east}
    \inheritanchor[from=diamond]{south west}
    \inheritanchor[from=diamond]{north west}
    \inheritanchor[from=diamond]{south east}    
    \backgroundpath{%
        \pgf@sh@bg@diamond% Steal the diamond background path
        \pgfmathparse{\pgfkeysvalueof{/pgf/crossed diamond shorten}}
        \ifpgfmathunitsdeclared%
            \outernortheast%
            \pgf@xa=\pgf@x%
            \pgf@ya=\pgf@y%
            \advance\pgf@xa by-\pgfmathresult pt\relax%
            \advance\pgf@ya by-\pgfmathresult pt\relax%
        \else
            \outernortheast%
            \pgfmathparse{1-\pgfmathresult}%
            \pgf@xa=\pgfmathresult\pgf@x%
            \pgf@ya=\pgfmathresult\pgf@y%
        \fi%
        \ifdim\pgf@xa>0pt%
            \pgfpathmoveto{\pgfqpoint{-\pgf@xa}{0pt}}%
            \pgfpathlineto{\pgfqpoint{\pgf@xa}{0pt}}%
        \fi%
        \ifdim\pgf@ya>0pt\relax%
            \pgfpathmoveto{\pgfqpoint{0pt}{\pgf@ya}}%
            \pgfpathlineto{\pgfqpoint{0pt}{-\pgf@ya}}%
        \fi%
    }
}
\makeatother

\begin{document}

\begin{tikzpicture}[diamond with cross/.style={
    crossed diamond, 
    crossed diamond shorten=#1,  
    draw,
    rounded corners=0.0625cm,
    minimum size=1cm,
    very thick,
}]
\foreach \s [count=\i from 0]in {0, 0.125, 0.5, 0.75, 0cm, 0.125cm, 0.25cm, 0.375cm}
    \node [diamond with cross=\s] at ({int(\i/4)*2}, {mod(\i, 4)*1.5}) {};

\end{tikzpicture}

\end{document}

Which produces this:

cross_diamond

When the key crossed diamond shorten contains units, this is taken as the absolute distance to shorten the cross "arms"; when no units are given the arms are shortened by the fraction of the full arm length. The bottom shapes, demonstrate the possibly undesirable results when using the full length.

share|improve this answer

I think there's still room for an answer exploiting the magic append after command. This solution creates two styles crossed diamond and rounded crossed diamond that automatically, after having drawn the diamond shape, append the cross drawing the necessary paths starting from the anchors of the node.

To customize the length of the cross, the two styles accept it as an argument, but there are default values in order to have a cross which touch exactly the borders of the diamond when the line width is not customized (this is because the default values are set based on \pgflinewidth).

The basic usage is very simple:

\tikz\node[minimum size=1cm,crossed diamond=2ex]{};

gives:

enter image description here

while

\tikz\node[minimum size=1cm,rounded crossed diamond=2ex]{};

gives:

enter image description here

The specification of the minimum size is recommended.

Here is a detailed list of examples and the necessary code:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\tikzset{
     crossed diamond/.style={
        diamond,
        draw,
        append after command={
            [every edge/.append style={
                shorten >=#1,
                shorten <=#1,
            }]
           (\tikzlastnode.north) edge (\tikzlastnode.south)
           (\tikzlastnode.east) edge (\tikzlastnode.west)
        },
    },
    crossed diamond/.default={\pgflinewidth},
    rounded crossed diamond/.style={
        rounded corners,
        crossed diamond={#1},
    },
    rounded crossed diamond/.default={4\pgflinewidth}
}

\begin{document}

\begin{tikzpicture}[minimum size=1cm, node distance=2cm]
\begin{scope}[blue]
\node[crossed diamond] (first) {};
\node[right of=first, crossed diamond={2ex}] (second) {};
\node[right of=second, crossed diamond={0.25cm}] (third) {};
\node[right of=third, crossed diamond={0.4cm}] (fourth) {};
\end{scope}
\begin{scope}[red]
\node[below of=first, rounded crossed diamond]  {};
\node[below of=second, rounded crossed diamond={2ex}]  {};
\node[below of=third,rounded crossed diamond={0.25cm}]  {};
\node[below of=fourth, rounded crossed diamond={0.4cm}] {};
\end{scope}
\end{tikzpicture}

\vspace*{1.5\baselineskip}

\begin{tikzpicture}[line width=1mm,minimum size=1.5cm, node distance=3cm]
\begin{scope}[blue]
\node[crossed diamond] (first) {};
\node[right of=first, crossed diamond={2ex}] (second) {};
\node[right of=second, crossed diamond={0.4cm}] (third) {};
\node[right of=third, crossed diamond={0.6cm}] (fourth) {};
\end{scope}
\begin{scope}[red]
\node[below of=first, rounded crossed diamond]  {};
\node[below of=second, rounded crossed diamond={2ex}]  {};
\node[below of=third,rounded crossed diamond={0.4cm}]  {};
\node[below of=fourth, rounded crossed diamond={0.6cm}] {};
\end{scope}
\end{tikzpicture}

\vspace*{1.5\baselineskip}

\begin{tikzpicture}[very thick,minimum size=2cm, node distance=3cm]
\begin{scope}[blue]
\node[crossed diamond] (first) {};
\node[right of=first, crossed diamond={2ex}] (second) {};
\node[right of=second, crossed diamond={0.5cm}] (third) {};
\node[right of=third, crossed diamond={0.75cm}] (fourth) {};
\end{scope}
\begin{scope}[red]
\node[below of=first, rounded crossed diamond]  {};
\node[below of=second, rounded crossed diamond={2ex}]  {};
\node[below of=third,rounded crossed diamond={0.5cm}]  {};
\node[below of=fourth, rounded crossed diamond={0.75cm}] {};
\end{scope}
\end{tikzpicture}

\end{document}

The result:

enter image description here

share|improve this answer

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.