Text FormattingAlign Counters and Equations side-by-side

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

Align Counters and Equations side-by-side

Post by ghostanime2001 »

I know that a) is aligned correctly with 5) but how do you align b) with 6) and c) with 7) ? Here is what my document looks like that I'm working on below MWE to get the real idea of what I mean. Below is my MWE.

Code: Select all

\documentclass[fleqn]{article}
\usepackage{fullpage}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amstext}
\usepackage{wasysym}
\usepackage{type1cm}
\usepackage{xfrac}
\usepackage{xspace}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage{pifont}
\usepackage{ulem}
\usepackage{fouridx}
\usepackage[shortlabels,inline]{enumitem} 
\usepackage[makeroom]{cancel}
\usepackage{siunitx}
\usepackage{mathtools} 
\usepackage[version=3]{mhchem}
\usepackage{chemmacros}
\usepackage{fix-cm}
\setlength{\parindent}{0in}
\setlength{\parskip}{0in}
\setlength{\mathindent}{0pt}
\allowdisplaybreaks
\pagestyle{empty}
\newcommand{\since}{\raisebox{0.56pt}{\rotatebox[origin=c]{180}{$\Large\wasytherefore$}}}
\newcommand{\thus}{\Large\wasytherefore}
\sisetup{inter-unit-product=\cdot,number-unit-product=\text{ },tight-spacing=true}
\begin{document}
\hfill \begin{minipage}[t]{2in}\begin{center}4.2 - Calculating Mass\end{center}\end{minipage}\hfill\llap{} \par\medskip
\begin{enumerate}[start=3,nosep,leftmargin=0in]
\item
$\begin{array}[t]{@{}ll@{}}
\begin{minipage}[t]{3in}\begin{enumerate}[a),nosep]\item eaglrbha;elr eaglrbha;elrgh'eejkggwerg \\ qeithqerihjgw'lerhjg'wrjehwerh \\ qeithqerihjgw'lerhjg'wrjehwerh \\ aaaaaaaaaaaaaaaaaaaaa \item eaglrbha;elrgh'eejkgwerg \\ qeithqqeithqqeithqerihjg \\ w'lerhjg'wrjehwerh \item eaglrbha;elrgh'eejkgwerg \\ qeithqerihjgw'lerhjg'wrjehw \\ erhqeithqerihjgw'lerhjg'wrjehwerh \\ qeithqerihjgw'lerhjg'wrjehwerh\end{enumerate}\end{minipage} & \begin{minipage}[t]{3in}\begin{enumerate}[1),nosep,start=5]\item eaglrbha;elrgh'eejkgwerg \\ qeithqerihjgw'lerhjg'wrjehwerh \item eaglrbha;elrgh'eejkgwerg \\ qeithqerihjgw'lerhjg'wrjehwerh \item eaglrbha;elrgh'eejkgwerg \\ qeithqerihjgw'lerhjg'wrjehwerh\end{enumerate}\end{minipage}
\end{array}$
\end{enumerate}
\end{document}
Below is my real document

Code: Select all

\documentclass[fleqn]{article}
\usepackage{fullpage}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amstext}
\usepackage{wasysym}
\usepackage{type1cm}
\usepackage{xfrac}
\usepackage{xspace}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage{pifont}
\usepackage{ulem}
\usepackage{fouridx}
\usepackage[shortlabels,inline]{enumitem} 
\usepackage[makeroom]{cancel}
\usepackage{siunitx}
\usepackage{mathtools} 
\usepackage[version=3]{mhchem}
\usepackage{chemmacros}
\usepackage{fix-cm}
\setlength{\parindent}{0in}
\setlength{\parskip}{0in}
\setlength{\mathindent}{0pt}
\allowdisplaybreaks
\pagestyle{empty}
\newcommand{\since}{\raisebox{0.56pt}{\rotatebox[origin=c]{180}{$\Large\wasytherefore$}}}
\newcommand{\thus}{\Large\wasytherefore}
\sisetup{inter-unit-product=\cdot,number-unit-product=\text{ },tight-spacing=true}
\begin{document}
\hfill \begin{minipage}[t]{2in}\begin{center}4.2 - Calculating Mass\end{center}\end{minipage}\hfill\llap{} \par\medskip
\begin{enumerate}[start=3,nosep,leftmargin=0in]
\item
$\begin{array}[t]{@{}ll@{}}
\begin{minipage}[t]{3in}\begin{enumerate}[a),nosep]\item $\begin{aligned}[t]\ce{m_{\ce{He2}}}&=\text{4.2 mol}\times\text{4 g/mol} \\ &=\text{16.8 g}\end{aligned}$ \item $\begin{aligned}[t]\ce{m_{\ce{Pb}}}&=\text{\num{8.11e-2} mol}\times\text{207.2 g/mol} \\ &=\text{16.8 g}\end{aligned}$ \item $\begin{aligned}[t]\ce{n_{\ce{He2}}}&=\dfrac{\text{\num{3.01e22} atoms}}{\text{\num{6.02e23} atoms}} \\ &=\text{0.05 mol}\end{aligned}$ \par\smallskip $\begin{aligned}[t]\ce{m_{\ce{He2}}}&=\text{0.05 mol}\times\text{4 g/mol} \\ &=\text{0.2 g}\end{aligned}$\end{enumerate}\end{minipage} & \begin{minipage}[t]{3in}\begin{enumerate}[1),nosep,start=5]\item $\begin{aligned}[t]\ce{n_{\ce{Na}}}&=\dfrac{\text{0.115 \cancel{g}}}{\text{23 \cancel{g}/mol}} \\ &=\text{0.005 mol}\end{aligned}$ \item $\begin{aligned}[t]\ce{n_{\ce{Pb}}}&=\dfrac{\text{\num{2.6e-3} \cancel{g}}}{\text{207.2 \cancel{g}/mol}} \\ &=\text{\num{1.25e-5} mol}\end{aligned}$ \item $\begin{aligned}[t]\ce{n_{\ce{P}}}&=\dfrac{\text{6.2 \cancel{g}}}{\text{31 \cancel{g}/mol}} \\ &=\text{0.2 mol}\end{aligned}$ \par\smallskip $\begin{aligned}[t]\ce{N_{\ce{P}}}&=\text{0.2 mol}\times\text{\num{6.02e23} atoms} \\ &=\text{\num{1.2e23} atoms}\end{aligned}$\end{enumerate}\end{minipage}
\end{array}$
\end{enumerate}
\end{document}

Recommended reading 2024:

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

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

User avatar
CDbile
Posts: 19
Joined: Mon Jan 31, 2011 6:48 pm

Align Counters and Equations side-by-side

Post by CDbile »

Well, I can't give you the code, but I can give you some ideas...

If you know TeX a little you know that when it begins to build the second minipage, the first one is only a big box and what is inside is forgotten, so you can't ask TeX to align the right part with the left part this way.

So, what I think you need to do is :
  • create a new environment,
  • with only one counter,
  • that you use to create two "pseudo-lists",
  • and that you build from left to right ((a), (5), (b), (6), etc.)
Edit: Oh, and clean your MWE, you don't need anything else than

Code: Select all

enumitem
here.
CDbile
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: Align Counters and Equations side-by-side

Post by ghostanime2001 »

1. How do I create a pseudo list ?
2. I don't know any Tex at all
3. i don't know the difference between TeX and LaTeX
4. How do I create a counter for a new environment and also why can't I use the standard latex enumerate counter with a created environment instead of having to create one my own?

Also, I don't understand what you mean by counter, do you mean the enumerate label? for example.. a)... b)....c) or 1. ... 2. .... 3. ? Also, how can I have ONE counter representing two lists? To me, it doesn't make much sense
User avatar
CDbile
Posts: 19
Joined: Mon Jan 31, 2011 6:48 pm

Align Counters and Equations side-by-side

Post by CDbile »

ghostanime2001 wrote: 2. I don't know any Tex at all
3. i don't know the difference between TeX and LaTeX
LaTeX is a set of macros defined to simplify document creation in TeX, which is the typesetting language behind. LaTeX can be basically viewed as a layer over TeX.
And, I really think you should know a little about it, because knowing how it works behind greatly simplifies error handling and typesetting your document. Every good LaTeX tutorial tells a few words about TeX (see http://www.latex-community.org/forum/vi ... =44&t=2177)
ghostanime2001 wrote: 1. How do I create a pseudo list ?
4. How do I create a counter for a new environment and also why can't I use the standard latex enumerate counter with a created environment instead of having to create one my own?

Also, I don't understand what you mean by counter, do you mean the enumerate label? for example.. a)... b)....c) or 1. ... 2. .... 3. ? Also, how can I have ONE counter representing two lists? To me, it doesn't make much sense
Now, I worked a little on this and have built the first draft of a solution (see below). It's not very customizable for now, so you should work on it or specify what you exactly want to do with this environment.

Code: Select all

\documentclass[fleqn]{article}
\usepackage[utf8]{inputenc}
\usepackage[shortlabels,inline]{enumitem}
\usepackage{calc}

\newcounter{custcount}
\newenvironment{custenv}[1]{%
	\setcounter{custcount}{1}
	
% Creates a single item in a tabular cell
	\newcommand{\custitem}[3]{%
		\begin{minipage}[t]{\linewidth}
			\begin{enumerate}[##1, start=##2+\value{custcount}]
				\item ##3
			\end{enumerate}
		\end{minipage}}

% One line in the tabular
	\newcommand{\custline}[2]{%
		\custitem{a)}{0}{##1} & \custitem{1)}{4}{##2}
		\addtocounter{custcount}{1}}
		
	\tabular{#1}}
	{\endtabular}

\begin{document}

\begin{custenv}{@{}p{2in}p{2in}@{}} % the argument of custenv is the format of the tabular
\custline{bob\\ bob}{bob}\\
\custline{bob}{bob}
\end{custenv}

\end{document}
Note the package calc in the preamble.
CDbile
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: Align Counters and Equations side-by-side

Post by ghostanime2001 »

Is % necessary for something?
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Align Counters and Equations side-by-side

Post by ghostanime2001 »

wow that's really close to something that I wanted.. HOWEVER!!!! I made another one like that except my codes is soooo different from yours. Even with all this research into LaTeX and surfing the Whole wide web im still not getting the things really experienced author's talk about.. works like tokens, key values, strings etc... but I really appreciate helping a rookie like me lol. My alternate code is:

Code: Select all

\begin{enumerate}[nosep,leftmargin=\labelsep,start=3]
\item
\begin{enumerate*}[label=\alph*)]
\item
\begin{minipage}[t]{2.5in}$\begin{array}[t]{@{}l@{}}
\begin{aligned}[t]\ce{m_{\ce{He2}}}&=\text{4.2 mol}\times\text{4 g/mol} \\ &=\text{16.8 g}\end{aligned}\end{array}$\end{minipage}	
\item[5)]
$\begin{array}[t]{@{}l@{}}
\begin{aligned}[t]\ce{n_{\ce{Na}}}&=\dfrac{\text{0.115 \cancel{g}}}{\text{23 \cancel{g}/mol}} \\ &=\text{0.005 mol}\end{aligned} 
\end{array}$ \\[0.5\baselineskip]
\item[b)]
\begin{minipage}[t]{2.5in}$\begin{array}[t]{@{}l@{}}
\begin{aligned}[t]\ce{m_{\ce{Pb}}}&=\text{\num{8.11e-2} mol}\times\text{207.2 g/mol} \\ &=\text{16.8 g}\end{aligned}\end{array}$\end{minipage}	
\item[6)]
$\begin{array}[t]{@{}l@{}}
\begin{aligned}[t]\ce{n_{\ce{Pb}}}&=\dfrac{\text{\num{2.6e-3} \cancel{g}}}{\text{207.2 \cancel{g}/mol}} \\ &=\text{\num{1.25e-5} mol}\end{aligned}
\end{array}$ \\[0.5\baselineskip]
\item[c)]
\begin{minipage}[t]{2.5in}$\begin{array}[t]{@{}l@{}}
\begin{aligned}[t]\ce{n_{\ce{He2}}}&=\dfrac{\text{\num{3.01e22} atoms}}{\text{\num{6.02e23} atoms}} \\ &=\text{0.05 mol}\end{aligned} \\ \\ \begin{aligned}[t]\ce{m_{\ce{He2}}}&=\text{0.05 mol}\times\text{4 g/mol} \\ &=\text{0.2 g}\end{aligned} \end{array}$\end{minipage}	
\item[7)]
$\begin{array}[t]{@{}l@{}}
\begin{aligned}[t]\ce{n_{\ce{P}}}&=\dfrac{\text{6.2 \cancel{g}}}{\text{31 \cancel{g}/mol}} \\ &=\text{0.2 mol}\end{aligned} \\ \\ \begin{aligned}[t]\ce{N_{\ce{P}}}&=\text{0.2 mol}\times\text{\num{6.02e23} atoms} \\ &=\text{\num{1.2e23} atoms}\end{aligned}
\end{array}$ \par\medskip
\end{enumerate*}
\end{enumerate}
Also another question, how can I put math environments in your example? for some odd reason I can't put aligned environment
User avatar
CDbile
Posts: 19
Joined: Mon Jan 31, 2011 6:48 pm

Align Counters and Equations side-by-side

Post by CDbile »

ghostanime2001 wrote:Is % necessary for something?
Here, they're not, sometimes they are when every space is important, so I put them "just in case" when I test things :).
ghostanime2001 wrote:wow that's really close to something that I wanted.. HOWEVER!!!! I made another one like that except my codes is soooo different from yours. Even with all this research into LaTeX and surfing the Whole wide web im still not getting the things really experienced author's talk about.. works like tokens, key values, strings etc... but I really appreciate helping a rookie like me lol.
Well, the idea behind your code is basically the same, but as you need to put the item number every time, I think I'll keep my code and change it a little for more customization :

Code: Select all

\documentclass[fleqn]{article}
\usepackage{fullpage}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amstext}
\usepackage{wasysym}
\usepackage{type1cm}
\usepackage{xfrac}
\usepackage{xspace}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage{pifont}
\usepackage{ulem}
\usepackage{fouridx}
\usepackage[shortlabels,inline]{enumitem}
\usepackage[makeroom]{cancel}
\usepackage{siunitx}
\usepackage{mathtools}
\usepackage[version=3]{mhchem}
\usepackage{chemmacros}
\usepackage{fix-cm}
\setlength{\parindent}{0in}
\setlength{\parskip}{0in}
\setlength{\mathindent}{0pt}
\allowdisplaybreaks
\pagestyle{empty}
\newcommand{\since}{\raisebox{0.56pt}{\rotatebox[origin=c]{180}{$\Large\wasytherefore$}}}
\newcommand{\thus}{\Large\wasytherefore}
\sisetup{inter-unit-product=\cdot,number-unit-product=\text{ },tight-spacing=true}
\usepackage{calc}

\newcounter{custcount}
\newenvironment{custenv}[5]{
   \setcounter{custcount}{1}
   
% Creates a single item in a tabular cell
   \newcommand{\custitem}[3]{
      \begin{minipage}[t]{\linewidth}
         \begin{enumerate}[##1, start=##2+\value{custcount}]
            \item ##3
         \end{enumerate}
      \end{minipage}}

% One line in the tabular
   \newcommand{\custline}[2]{
      \custitem{#2}{#3}{##1} & \custitem{#4}{#5}{##2}
      \addtocounter{custcount}{1}}
      
   \tabular{#1}}
   {\endtabular}

\begin{document}

\begin{custenv}{@{}p{2in}p{2in}@{}} % first argument of custenv is the format of the tabular
	{a)}{0} % then, format of the left list
	{1)}{4} % and format fo the right list
\custline{$\begin{array}[t]{@{}l@{}}
\begin{aligned}[t]\ce{m_{\ce{He2}}}&=\text{4.2 mol}\times\text{4 g/mol} \\ &=\text{16.8 g}
\end{aligned}\end{array}$}{bob}\\
\custline{bob}{bob}
\end{custenv}

\end{document}
The main change is that I complexified "custenv" a little, it has 5 args now, but they are explained in the code, you will understand it easily (I hope !). With that you'll be able to reuse "custenv" in cases with different numbering.
ghostanime2001 wrote:Also another question, how can I put math environments in your example? for some odd reason I can't put aligned environment
Yes, That was because I hadn't loaded amsmath. With your packages it will work, but don't forget to add \usepackage{calc}.
CDbile
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Align Counters and Equations side-by-side

Post by ghostanime2001 »

How can I place a top centered "outer-counter" on this array-like set of equations? For example something like:
3. a) ...... b) (the ... are for empty horizontal space)

Code: Select all

\documentclass{article}
\usepackage[shortlabels]{enumitem} 
\usepackage{calc} 
\newcounter{custcount}\newenvironment{custenv}[5]{\setcounter{custcount}{1}\newcommand{\custitem}[3]{\begin{minipage}[t]{1in}\begin{enumerate}[##1,start=##2+\value{custcount}]\item ##3\end{enumerate}\end{minipage}}\newcommand{\custline}[2]{\custitem{#2}{#3}{##1} & \custitem{#4}{#5}{##2} \addtocounter{custcount}{1}}\tabular{#1}}{\endtabular} 
\begin{document} 
\begin{enumerate}[start=3]
\item
\begin{custenv}{@{}ll@{}}
{a)}{0}
{1)}{4}
\custline{1}{2} \\ 
\custline{3}{4} \\
\custline{5}{6} \\
\custline{7}{8} 
\end{custenv}
\end{enumerate}
\end{document}
User avatar
CDbile
Posts: 19
Joined: Mon Jan 31, 2011 6:48 pm

Align Counters and Equations side-by-side

Post by CDbile »

In the custenv environment, just add [t] after \tabular :

Code: Select all

\tabular[t]{#1}}{\endtabular}
CDbile
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: Align Counters and Equations side-by-side

Post by ghostanime2001 »

What about using horizontal length parameters like for example \labelsep, \leftmargin, \labelwidth, align=left,right or widest= ???
Post Reply