
Code
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \a in {0,45,...,315}%
{\node[line width = 0pt,
rotate = \a,
anchor = west,
inner sep = 0pt,
opacity = .5]{\rule{.5cm}{.1cm}};}%
\end{tikzpicture}
\end{document}
I would to get the same result with \rotatebox and \put but other interesting methods are allowed without TikZ.
Some explanations of the first code :
anchor = westis the most important if we want to place the rules at the same pointinner sep = 0ptto remove white space around the rule (> 0pt -> pretty pictures)line width = 0psubtlety! without this a small white point appears at the centeropacity = .5only to watch how the rules are placed.
First try
\documentclass{article}
\usepackage{tikz} % I keep TikZ because `foreach` is useful
\begin{document}
\begin{picture}(0,0)
\foreach \a in {0,45,...,315}%
{\put(0,0){\rotatebox[origin=l]{\a}{\mbox{\rule{.5cm}{.1cm}}}}}%
\end{picture}
\end{document}

It's normal because the boxes are misplaced, we can see why if we remove put:

I'm a serious guy so I found this question and some good and useful answers so ...
Second try
\documentclass{article}
\usepackage{tikz}
\makeatletter
\newcommand{\somespecialrotate}[3][]{%
\begingroup
\sbox\@tempboxa{\rotatebox[#1]{#2}{#3}}%
\@tempdima=-\wd\@tempboxa
\advance\@tempdima by 0.09cm % this is one of the problem
\mbox{\hskip\@tempdima\usebox\@tempboxa}%
\endgroup}%
\makeatother
\begin{document}
\begin{picture}(0,0)
\foreach \a in {-90,-45,...,90}%
{\put(0,0){\rotatebox[origin=l]{\a}{\mbox{\rule{.5cm}{.1cm}}}}}%
\put(0,0){\somespecialrotate[origin=l]{180}{\mbox{\rule{.5cm}{.1cm}}}}%
\put(0,0){\somespecialrotate[origin=l]{135}{\mbox{\rule{.5cm}{.1cm}}}}%
\put(0,0){\somespecialrotate[origin=l]{225}{\mbox{\rule{.5cm}{.1cm}}}}%
\end{picture}
\end{document}

This looks fine but \advance\@tempdima by 0.09cm is not serious and if I compare with the first code

\documentclass{article}
\usepackage{tikz}
\makeatletter
\newcommand{\somespecialrotate}[3][]{%
\begingroup
\sbox\@tempboxa{\rotatebox[#1]{#2}{#3}}%
\@tempdima=-\wd\@tempboxa
\advance\@tempdima by 0.09cm % this is one of the problem
\mbox{\hskip\@tempdima\usebox\@tempboxa}%
\endgroup}%
\makeatother
\begin{document}
\begin{picture}(0,0)
\foreach \a in {-90,-45,...,90}%
{\put(0,0){\rotatebox[origin=l]{\a}{\mbox{\rule{.5cm}{.1cm}}}}}%
\put(0,0){\somespecialrotate[origin=l]{180}{\mbox{\rule{.5cm}{.1cm}}}}%
\put(0,0){\somespecialrotate[origin=l]{135}{\mbox{\rule{.5cm}{.1cm}}}}%
\put(0,0){\somespecialrotate[origin=l]{225}{\mbox{\rule{.5cm}{.1cm}}}}%
\end{picture}%
\color{red}%
\begin{tikzpicture} [overlay]
\foreach \a in {0,45,...,315}%
{\node[rotate=\a,anchor=west,inner sep=0pt,opacity=.5]{\rule{.5cm}{.1cm}};}%
\end{tikzpicture}
\end{document}
My question How to get the same picture with putand rotatebox?


pgfforpackage is the one responsible for the\foreachgoodies. So you can skip TikZ and load onlypgfforpackage. – percusse Feb 28 '12 at 10:29