I searched really hard but I was not able to find a solution to my problem. I want to draw a parallelogramm with tikz in LaTeX. Then, I want to shade the parallelogramm parallel to the sides of it (which are not horizontal/vertical but somehow diagonal. I only found possibilities to shade the parallelogram horizontal/vertical independent of the orientation of the parallelogram.
Asked
Active
Viewed 2,345 times
8
-
Welcome to very great world of TeX.SE. – Sebastiano Jul 25 '18 at 20:11
-
1Do you mean adding a shadow to a parallelogram, or hatching a parallelogram parallel to a side ? – Bernard Jul 25 '18 at 20:33
3 Answers
9
Using the key shading angle=<> you can rotate the shading in whatever direction you want. If you need even more fine control, you could also define you own shading, see section 109.3 of the tikz manual for this.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
\node[trapezium, draw,trapezium left angle=120, trapezium right angle=60,shade,shading=axis,shading angle=100] at (0,0) {};
\end{tikzpicture}
\end{document}
samcarter_is_at_topanswers.xyz
- 158,329
-
I hoped there was any other solution than rotating the shading by an angle because am drawing with tikz-3dplot something threedimensional and therefore I don't even know the exact angle (I'm using coordinates and not trapezum), but I assume that I'll have to do it like this. – user449911 Jul 25 '18 at 20:26
-
-
@user449911 If this does not solve your problem, there is no need to accept it. But maybe it would be good to include the additional info about the unknown angle in your question, so that future answers know about this. – samcarter_is_at_topanswers.xyz Jul 25 '18 at 20:30
-
@user449911 can you maybe include an image of the shape you are trying to draw? Maybe there is another workaround. – samcarter_is_at_topanswers.xyz Jul 25 '18 at 20:32
4
An option using basic iterative tricks, to make fake shading, but it is pure 2D, If you want a real 3D result you must see Asymptote to obtain results like this How to create horn torus in latex?, also pgf-plots allows to manage surface colors like in example_171.pdf.
MWE:
% arara: pdflatex: {synctex: yes, action: nonstopmode}
% arara: animate: {density: 200, delay: 20, other: -background white -alpha remove}
% arara: showanimate
\documentclass[tikz,border=20pt]{standalone}
\usepackage{tkz-euclide}
\usetikzlibrary{calc}
\usetkzobj{all}
\begin{document}
\foreach \A in {0,1,...,15,14,13,...,0}{
\begin{tikzpicture}
% Set limits.
\tkzInit[xmax=7,xmin=-2,ymax=4, ymin=-3.5]
\tkzGrid[sub,color=blue!20!,subxstep=.5,subystep=.5]
\tkzClip
%Define principal points.
\tkzDefPoint(\A*0.05,-1+\A*0.1){A}
\tkzDefPoint(2-\A*0.2,-\A*0.15){B}
\tkzDefPoint(3+\A*0.08,2-\A*0.1){C}
\tkzDefLine[parallel=through C](B,A) \tkzGetPoint{D}
%Label the points
\tkzLabelPoints[color=blue,below=5pt](A,B)
\tkzLabelPoints[color=blue,above=5pt](C,D)
% Draw all the shades.
\foreach \i in {0,1,...,30}{
\node(m) at ($(D)!\i/30!(A)$){};
\node(n) at ($(C)!\i/30!(B)$){};
\fill [blue, fill opacity=1/30]
(A) -- (m.center) -- (n.center) -- (B) -- cycle;
}
%Draw the segments
\tkzDrawSegments[thick](A,B B,C C,D D,A)
\end{tikzpicture}}
\end{document}
PSD: It generates a pdf document with animation frames, to convert into .gif I use Imagemagick converter
J Leon V.
- 11,533
- 16
- 47
-
This doesnt seem to be a simple or smooth solution but at least it worked for me, thank you! – user449911 Jul 26 '18 at 13:55
3
A PSTricks solution.
\documentclass[pstricks,border=10mm]{standalone}
\begin{document}
\foreach \i in {0,10,...,170}{%
\begin{pspicture}(6,4)
\pspolygon[fillstyle=vlines,hatchangle=\i](0,0)(4,0)(6,4)(2,4)
\rput*(3,2){$\i^\circ$}
\end{pspicture}}
\end{document}
Another version
\documentclass[pstricks,border=10mm]{standalone}
\begin{document}
\foreach \i in {0,10,...,80}{%
\begin{pspicture}(6,4)
\pspolygon[fillstyle=crosshatch,hatchcolor=red,hatchangle=\i](0,0)(4,0)(6,4)(2,4)
\rput*(3,2){$\i^\circ$}
\end{pspicture}}
\end{document}
D G
- 342



