Graphics, Figures & TablesTiKz (\foreach): reversing arrows

Information and discussion about graphics, figures & tables in LaTeX documents.
Sundial
Posts: 57
Joined: Thu Apr 19, 2012 7:28 pm

TiKz (\foreach): reversing arrows

Post by Sundial »

The upper group of triangle shaped arrows should be reversed until nullifying the one on the top, in order to have the column antisymmetrically loaded. Thanks in advance.
Solved what said in next note, figure just uploaded:
----------------
PS: unable to attach the suitable screenshot. Why not allowed by the forum platform? A figure is often better than thousands of words!
--------

Code: Select all

\documentclass{article}
\usepackage{tikz}            
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{center}
\setlength\PreviewBorder{10pt}

\tikzstyle{axis}   = [-latex,blue!55]

\tikzstyle{two}=[x={(0.75cm,0cm)},y={(0cm,0.75cm)}]

\begin{document}
\begin{center}
  \begin{tikzpicture}[two]
        \coordinate (O) at (0,0);
        \draw[axis] (O) -- ++(4,0) node[right] {$x$};
        \draw[axis] (O) -- ++(0,6) node[above] {$y$};
        
% --- 1 ----
    \foreach \y in {0.5,0.75,...,2.5} { % 1st triangle shaped arrows
      \draw[-latex] (-1*\y/2.5,\y) -- (0,\y);
    }
% --- 2 ----    
    \foreach \y in {2.5,2.75,...,5} { % (trouble) 2nd triangle shaped arrows
      \draw[-latex] (1*\y/2.5,\y) -- (0,\y);
    }    

  \end{tikzpicture} 
\end{center}
\end{document}
%
Attachments
rev-arr.png
rev-arr.png (7.1 KiB) Viewed 7184 times
Last edited by Sundial on Mon Apr 20, 2015 7:24 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

TiKz (\foreach): reversing arrows

Post by Stefan Kottwitz »

Sundial wrote:unable to attach the suitable screenshot. Why not allowed by the forum platform? A figure is often better than thousands of words!
It is allowed. What did you try? Use some words to explain what you did for attaching, because jpg and png and such are allowed and I cannot guess what you tried.

Stefan
LaTeX.org admin
Sundial
Posts: 57
Joined: Thu Apr 19, 2012 7:28 pm

TiKz (\foreach): reversing arrows

Post by Sundial »

Simply said, Stefan. Both tags Img and URL need to catch images from external links[http://...bla,bla,bla], not from the user's computer (mine, I mean, where the screenshot is located), as it happens in many similar platforms in the world! Cheers
User avatar
Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

TiKz (\foreach): reversing arrows

Post by Stefan Kottwitz »

Sundial wrote:Both tags Img and URL need to catch images from external links
Sure, those are links. But you said attach, and we definitely support attachments. Click on "Upload attachment" below the post edit field.

Stefan
LaTeX.org admin
Sundial
Posts: 57
Joined: Thu Apr 19, 2012 7:28 pm

Re: TiKz (\foreach): reversing arrows

Post by Sundial »

Thank you, Stefan! The solution of my troubles was ... under my nose! Figure properly att'd in the opening post. Cheers
Sundial
Posts: 57
Joined: Thu Apr 19, 2012 7:28 pm

TiKz (\foreach): reversing arrows

Post by Sundial »

One more latex code, just to show a manually (and deprecated) way to draw upper arrows. Awaiting for the wished drift. Thx&Cheers

Code: Select all

\documentclass{article}
\usepackage{tikz} 
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{center}
\setlength\PreviewBorder{10pt}

\tikzstyle{axis} = [-latex,blue!55]

\tikzstyle{two}=[x={(0.75cm,0cm)},y={(0cm,0.75cm)}]

\begin{document}
\begin{center}
\begin{tikzpicture}[two]
\coordinate (O) at (0,0);
\draw[axis] (O) -- ++(4,0) node[right] {$x$};
\draw[axis] (O) -- ++(0,6) node[above] {$y$};

% --- 1 ----
\foreach \y in {0.5,0.75,...,2.5} { % 1st triangle shaped arrows
\draw[-latex] (-1*\y/2.5,\y) -- (0,\y);
}

% --- 2 ---- 
%\foreach \y in {2.5,2.75,...,5} { % (trouble) 2nd triangle shaped arrows
%\draw (1*\y/2.5,\y) -- (0,\y);
%}
% -------- Deprecated: manually drawing of upper arrows -----------
%                      ... just to show what I'm looking for -------
\draw[-latex] (1,2.5) -- (0,2.5);
\draw[-latex] (0.9,2.75) -- (0,2.75);
\draw[-latex] (0.8,3) -- (0,3); 
\draw[-latex] (0.7,3.25) -- (0,3.25); 
\draw[-latex] (0.6,3.5) -- (0,3.5); 
\draw[-latex] (0.5,3.75) -- (0,3.75); 
\draw[-latex] (0.4,4) -- (0,4); 
\draw[-latex] (0.3,4.25) -- (0,4.25); 
\draw[-latex] (0.2,4.5) -- (0,4.5); 
%\draw[-latex] (0.05,4.75) -- (0,4.75); 
%\draw[-latex] (0,5) -- (0,5); % zero lenght arrow
% ----------------------------------------------------------------------
%
% Contours
\draw [blue] (0,0) -- (-1,2.5); % closing queues lower arrows
\draw [red] (0,5) -- (1,2.5); % closing queues upper arrows

\end{tikzpicture} 
\end{center}
\end{document}
Last edited by Stefan Kottwitz on Mon Apr 20, 2015 12:27 pm, edited 1 time in total.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

TiKz (\foreach): reversing arrows

Post by Stefan Kottwitz »

I see! So you just need the correct math calculation of the x coordinate. Use this:

Code: Select all

\foreach \y in {2.5,2.75,...,4.5} {
  \draw[-latex] (2-\y/2.5,\y) -- (0,\y);}
arrows.png
arrows.png (8.59 KiB) Viewed 7174 times
It's like x=(5-y)/2.5.

Stefan
LaTeX.org admin
Sundial
Posts: 57
Joined: Thu Apr 19, 2012 7:28 pm

TiKz (\foreach): reversing arrows

Post by Sundial »

So good, Stefan! Now the code works properly. The \foreach command has a really strong powerfulness, so I should study it for several applications in structural engineering. Thank you very much and best wishes.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

TiKz (\foreach): reversing arrows

Post by Johannes_B »

Structural engineering? You might be interested in TikZ Library for Structural Analysis.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Sundial
Posts: 57
Joined: Thu Apr 19, 2012 7:28 pm

TiKz (\foreach): reversing arrows

Post by Sundial »

Johannes_B wrote:Structural engineering? You might be interested in TikZ Library for Structural Analysis.
Hi Johannes, I've faced that lib a couple of years ago, without satisfaction, unfortunately! Plenty of commands to learn and great difficulty to draw simple load schemes as the above, just solved. This is, of course, my opinion. Please, stay tuned to look at my next post. Cheers
Post Reply