Graphics, Figures & TablesCustomize uparrow and downarrow

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
bstex
Posts: 69
Joined: Mon Oct 23, 2017 10:22 am

Customize uparrow and downarrow

Post by bstex »

Hi.
I'm using the mhchem package and I'd like to have custom arrows in my text.
Rightarrow, leftarrow and doublearrow are fine with my custom design, but why uparrow and downarrow are not shown with my custom design?
Screen Shot 2018-06-21 at 18.55.57.png
Screen Shot 2018-06-21 at 18.55.57.png (13.93 KiB) Viewed 6258 times
My MWE:

Code: Select all

\documentclass[a4paper,11pt]{book}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta}
\usepackage[version=4]{mhchem}

\begin{document}

\ExplSyntaxOn
\cs_set:Npn \__mhchem_arrow_options_minLength:n  { {1.25em} }
\ExplSyntaxOff

\mhchemoptions{arrows=pgf{Straight Barb[round, angle=60:1.5pt 3]}{0.1ex}}
\ce{A -> B} \\
\ce{C <- D} \\
\ce{E <=> F} \\
\ce{G ^} \\
\ce{H v} \\

\end{document}
Thank you very much.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Customize uparrow and downarrow

Post by Stefan Kottwitz »

mhchem does the customization only for horizontal arrows.

Here is a quick idea, taking the customized arrows and rotating them:

Code: Select all

\renewcommand{\uparrow}{\raisebox{0.3ex}{\rotatebox[origin=c]{90}{\ce{->}}}} 
\renewcommand{\downarrow}{\raisebox{0.3ex}{\rotatebox[origin=c]{-90}{\ce{->}}}}
mhchem.png
mhchem.png (10.13 KiB) Viewed 6219 times
Stefan
LaTeX.org admin
bstex
Posts: 69
Joined: Mon Oct 23, 2017 10:22 am

Customize uparrow and downarrow

Post by bstex »

Pretty good, but this way the uparrow and downarrow have a little bit larger length than they should.
Screen Shot 2018-06-23 at 16.05.12.png
Screen Shot 2018-06-23 at 16.05.12.png (8.74 KiB) Viewed 6216 times
Since the length of the arrows is defined in preamble with:

Code: Select all

\ExplSyntaxOn
\cs_set:Npn \__mhchem_arrow_options_minLength:n  { {1.25em} }
\ExplSyntaxOff
is it possible to make shorter only the up and down arrows?
Thank you Stefan for your reply.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Customize uparrow and downarrow

Post by Stefan Kottwitz »

The arrow could be scaled so it has the same proportions as the horizontal one:

Code: Select all

\renewcommand{\uparrow}{\scalebox{0.68}{\raisebox{0.75ex}{\rotatebox[origin=c]{90}{\ce{->}}}}}
\renewcommand{\downarrow}{\scalebox{0.66}{\raisebox{0.78ex}{\rotatebox[origin=c]{-90}{\ce{->}}}}}

Stefam
LaTeX.org admin
bstex
Posts: 69
Joined: Mon Oct 23, 2017 10:22 am

Customize uparrow and downarrow

Post by bstex »

That's a solution, sure, but I need to shorten only the length of the arrow, not to shrink it.
Thank you again.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Customize uparrow and downarrow

Post by Stefan Kottwitz »

Ok...

Code: Select all

\ExplSyntaxOn
\renewcommand \uparrow {
  \raisebox {0.4ex} {
  \rotatebox [origin=c] {90} {
  \cs_set:Npn \__mhchem_arrow_options_minLength:n  { {0.85em} }
  \ce{->}}}
}
\renewcommand \downarrow {
  \raisebox {0.4ex} {
  \rotatebox [origin=c] {-90} {
  \cs_set:Npn \__mhchem_arrow_options_minLength:n  { {0.85em} }
  \ce{->}}}
}
\ExplSyntaxOff
mhchem-arrows.png
mhchem-arrows.png (10.54 KiB) Viewed 6210 times

Stefan
LaTeX.org admin
bstex
Posts: 69
Joined: Mon Oct 23, 2017 10:22 am

Customize uparrow and downarrow

Post by bstex »

Oh, that was too complex for me to do.
Thank you very much, Stefan.
Post Reply