Text FormattingTrue align ding number with baseline of text

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

True align ding number with baseline of text

Post by ghostanime2001 »

How do you properly align the the baseline of a ding symbol, say \ding{192} with the baseline of the surrounding text? I have already tried using \raisebox but it is too technical (and I don't mean the syntax) but finding the right amount to raise or lower. Isn't there a better and more non-ambiguous way of aligning of symbols with the baseline of text surrounding the ding symbol?

Code: Select all

\documentclass[fleqn]{article} 
\usepackage{amsmath}
\usepackage[shortlabels,inline]{enumitem}
\usepackage[version=3]{mhchem}
\usepackage{pifont}
\setlength{\parindent}{0in}
\setlength{\parskip}{0in}
\setlength{\mathindent}{0in}
\newlist{longenum}{enumerate}{6}
\setlist[longenum,1]{label=\arabic*.}
\setlist[longenum,2]{label=\alph*)}
\setlist[longenum,3]{label=\alph*)}
\setlist[longenum,4]{label=(\roman*)}
\setlist[longenum,5]{label=(\alph*)}
\setlist[longenum,6]{label=\roman*)}
\begin{document}
\begin{longenum}[nosep,leftmargin=0in]
\item Hello \\
\begin{array}[t]{@{}ll@{}}
\begin{minipage}[t]{2cm}$\left(-1\right)\times$\begin{longenum}[leftmargin=0in]\item[\ding{192}] \ce{H2O}\end{longenum}\end{minipage}
\end{array}
\end{longenum}
\end{document}
In here, I want to make the "(-1) x" be in the same line as (1) (the parantheses mean circle) H2O and as big as need be to align like the following attached picture.
Attachments
ding-alignment.png
ding-alignment.png (18.97 KiB) Viewed 8106 times
Last edited by ghostanime2001 on Fri Dec 16, 2011 11:44 pm, 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.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: True align ding number with baseline of text

Post by localghost »

Just for your information. The Dingbat character is aligned properly to the baseline. I'm afraid you misunderstood something. The baseline is the bottom of characters that don't have a descender (like "a" or "b"). The lower line you inserted in the picture almost marks the depth of characters with a descender (like "g" or "j"). The Dingbat character has no depth, thus its bottom sits on the baseline.


Thorsten
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

True align ding number with baseline of text

Post by cgnieder »

You need to learn how to make a real minimal working example...

Maybe something like this?

Code: Select all

\documentclass{scrartcl}
\usepackage[version=3]{mhchem}
\usepackage{pifont}

\begin{document}

\ce{\left(-1\right)\times \raise-.2ex\hbox{\ding{192}}~ H2O}

\end{document}
site moderator & package author
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Re: True align ding number with baseline of text

Post by cgnieder »

Ah, and I need to learn to read... You didn't want to use a raisebox or similar ...
site moderator & package author
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

True align ding number with baseline of text

Post by cgnieder »

Then this might be what you want:

Code: Select all

\documentclass{scrartcl}
\usepackage[version=3]{mhchem}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=1pt] (char) {#1};}}

\begin{document}

\ce{\left(-1\right)\times \circled{1}~ H2O}

\end{document}
PS: I stole the code for the \circled command here.
site moderator & package author
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

True align ding number with baseline of text

Post by localghost »

cgnieder wrote:[…] I stole the code for the \circled command here.
This command has also been presented several times here on the board.

[1] View topic: Circled Number
[2] View topic: »1« within a Circle (note the questioner!)
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Re: True align ding number with baseline of text

Post by cgnieder »

true, but that's not where I copied it from ;)
site moderator & package author
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: True align ding number with baseline of text

Post by ghostanime2001 »

What is the ~ for?
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Re: True align ding number with baseline of text

Post by cgnieder »

The "~" is a non-breaking space. Without it the "\circled{1}" and the "H20" are too close together in my opinion. You might want to play with \; \, and so on for proper spacing...

Best
site moderator & package author
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

True align ding number with baseline of text

Post by ghostanime2001 »

How do you align the 1 and 2 in circles vertically in this. Your help was helpful haha

Code: Select all

    \documentclass{scrartcl}
    \usepackage[version=3]{mhchem}
    \usepackage{tikz}
    \newcommand{\ci}[1]{\tikz[baseline=(char.base)]{\node[shape=circle,draw,inner sep=1pt] (char) {#1};}}
    \begin{document}
$\begin{aligned}[t]\left(-1\right)\times\ci{1}~\ce{H2O + KCl -> NH2 + CO2} \\ \ci{2}~\ce{H2O -> CO3 + H3O+}\end{aligned}$
\end{document}
Post Reply