LaTeX forum ⇒ 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

Postby ghostanime2001 » Tue Oct 18, 2011 1:09 am

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.

  1. \documentclass[fleqn]{article}
  2. \usepackage{fullpage}
  3. \usepackage[margin=1in]{geometry}
  4. \usepackage{amsmath}
  5. \usepackage{amsthm}
  6. \usepackage{amsfonts}
  7. \usepackage{amssymb}
  8. \usepackage{amstext}
  9. \usepackage{wasysym}
  10. \usepackage{type1cm}
  11. \usepackage{xfrac}
  12. \usepackage{xspace}
  13. \usepackage[T1]{fontenc}
  14. \usepackage[utf8]{inputenc}
  15. \usepackage{textcomp}
  16. \usepackage{pifont}
  17. \usepackage{ulem}
  18. \usepackage{fouridx}
  19. \usepackage[shortlabels,inline]{enumitem}
  20. \usepackage[makeroom]{cancel}
  21. \usepackage{siunitx}
  22. \usepackage{mathtools}
  23. \usepackage[version=3]{mhchem}
  24. \usepackage{chemmacros}
  25. \usepackage{fix-cm}
  26. \setlength{\parindent}{0in}
  27. \setlength{\parskip}{0in}
  28. \setlength{\mathindent}{0pt}
  29. \allowdisplaybreaks
  30. \pagestyle{empty}
  31. \newcommand{\since}{\raisebox{0.56pt}{\rotatebox[origin=c]{180}{$\Large\wasytherefore$}}}
  32. \newcommand{\thus}{\Large\wasytherefore}
  33. \sisetup{inter-unit-product=\cdot,number-unit-product=\text{ },tight-spacing=true}
  34. \begin{document}
  35. \hfill \begin{minipage}[t]{2in}\begin{center}4.2 - Calculating Mass\end{center}\end{minipage}\hfill\llap{} \par\medskip
  36. \begin{enumerate}[start=3,nosep,leftmargin=0in]
  37. \item
  38. $\begin{array}[t]{@{}ll@{}}
  39. \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}
  40. \end{array}$
  41. \end{enumerate}
  42. \end{document}

Below is my real document
  1. \documentclass[fleqn]{article}
  2. \usepackage{fullpage}
  3. \usepackage[margin=1in]{geometry}
  4. \usepackage{amsmath}
  5. \usepackage{amsthm}
  6. \usepackage{amsfonts}
  7. \usepackage{amssymb}
  8. \usepackage{amstext}
  9. \usepackage{wasysym}
  10. \usepackage{type1cm}
  11. \usepackage{xfrac}
  12. \usepackage{xspace}
  13. \usepackage[T1]{fontenc}
  14. \usepackage[utf8]{inputenc}
  15. \usepackage{textcomp}
  16. \usepackage{pifont}
  17. \usepackage{ulem}
  18. \usepackage{fouridx}
  19. \usepackage[shortlabels,inline]{enumitem}
  20. \usepackage[makeroom]{cancel}
  21. \usepackage{siunitx}
  22. \usepackage{mathtools}
  23. \usepackage[version=3]{mhchem}
  24. \usepackage{chemmacros}
  25. \usepackage{fix-cm}
  26. \setlength{\parindent}{0in}
  27. \setlength{\parskip}{0in}
  28. \setlength{\mathindent}{0pt}
  29. \allowdisplaybreaks
  30. \pagestyle{empty}
  31. \newcommand{\since}{\raisebox{0.56pt}{\rotatebox[origin=c]{180}{$\Large\wasytherefore$}}}
  32. \newcommand{\thus}{\Large\wasytherefore}
  33. \sisetup{inter-unit-product=\cdot,number-unit-product=\text{ },tight-spacing=true}
  34. \begin{document}
  35. \hfill \begin{minipage}[t]{2in}\begin{center}4.2 - Calculating Mass\end{center}\end{minipage}\hfill\llap{} \par\medskip
  36. \begin{enumerate}[start=3,nosep,leftmargin=0in]
  37. \item
  38. $\begin{array}[t]{@{}ll@{}}
  39. \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}
  40. \end{array}$
  41. \end{enumerate}
  42. \end{document}

Tags:

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

Postby CDbile » Thu Nov 03, 2011 10:28 pm

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 here.
CDbile

ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Postby ghostanime2001 » Fri Nov 04, 2011 2:54 am

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

Postby CDbile » Fri Nov 04, 2011 7:24 pm

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 viewtopic.php?f=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.

  1. \documentclass[fleqn]{article}
  2. \usepackage[utf8]{inputenc}
  3. \usepackage[shortlabels,inline]{enumitem}
  4. \usepackage{calc}
  5.  
  6. \newcounter{custcount}
  7. \newenvironment{custenv}[1]{%
  8. \setcounter{custcount}{1}
  9.  
  10. % Creates a single item in a tabular cell
  11. \newcommand{\custitem}[3]{%
  12. \begin{minipage}[t]{\linewidth}
  13. \begin{enumerate}[##1, start=##2+\value{custcount}]
  14. \item ##3
  15. \end{enumerate}
  16. \end{minipage}}
  17.  
  18. % One line in the tabular
  19. \newcommand{\custline}[2]{%
  20. \custitem{a)}{0}{##1} & \custitem{1)}{4}{##2}
  21. \addtocounter{custcount}{1}}
  22.  
  23. \tabular{#1}}
  24. {\endtabular}
  25.  
  26. \begin{document}
  27.  
  28. \begin{custenv}{@{}p{2in}p{2in}@{}} % the argument of custenv is the format of the tabular
  29. \custline{bob\\ bob}{bob}\\
  30. \custline{bob}{bob}
  31. \end{custenv}
  32.  
  33. \end{document}


Note the package calc in the preamble.
CDbile

ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Postby ghostanime2001 » Sat Nov 05, 2011 1:24 am

Is % necessary for something?

ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Postby ghostanime2001 » Sat Nov 05, 2011 5:25 am

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:

  1. \begin{enumerate}[nosep,leftmargin=\labelsep,start=3]
  2. \item
  3. \begin{enumerate*}[label=\alph*)]
  4. \item
  5. \begin{minipage}[t]{2.5in}$\begin{array}[t]{@{}l@{}}
  6. \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}
  7. \item[5)]
  8. $\begin{array}[t]{@{}l@{}}
  9. \begin{aligned}[t]\ce{n_{\ce{Na}}}&=\dfrac{\text{0.115 \cancel{g}}}{\text{23 \cancel{g}/mol}} \\ &=\text{0.005 mol}\end{aligned}
  10. \end{array}$ \\[0.5\baselineskip]
  11. \item[b)]
  12. \begin{minipage}[t]{2.5in}$\begin{array}[t]{@{}l@{}}
  13. \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}
  14. \item[6)]
  15. $\begin{array}[t]{@{}l@{}}
  16. \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}
  17. \end{array}$ \\[0.5\baselineskip]
  18. \item[c)]
  19. \begin{minipage}[t]{2.5in}$\begin{array}[t]{@{}l@{}}
  20. \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}
  21. \item[7)]
  22. $\begin{array}[t]{@{}l@{}}
  23. \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}
  24. \end{array}$ \par\medskip
  25. \end{enumerate*}
  26. \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

Postby CDbile » Sat Nov 05, 2011 6:04 pm

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 :

  1. \documentclass[fleqn]{article}
  2. \usepackage{fullpage}
  3. \usepackage[margin=1in]{geometry}
  4. \usepackage{amsmath}
  5. \usepackage{amsthm}
  6. \usepackage{amsfonts}
  7. \usepackage{amssymb}
  8. \usepackage{amstext}
  9. \usepackage{wasysym}
  10. \usepackage{type1cm}
  11. \usepackage{xfrac}
  12. \usepackage{xspace}
  13. \usepackage[T1]{fontenc}
  14. \usepackage[utf8]{inputenc}
  15. \usepackage{textcomp}
  16. \usepackage{pifont}
  17. \usepackage{ulem}
  18. \usepackage{fouridx}
  19. \usepackage[shortlabels,inline]{enumitem}
  20. \usepackage[makeroom]{cancel}
  21. \usepackage{siunitx}
  22. \usepackage{mathtools}
  23. \usepackage[version=3]{mhchem}
  24. \usepackage{chemmacros}
  25. \usepackage{fix-cm}
  26. \setlength{\parindent}{0in}
  27. \setlength{\parskip}{0in}
  28. \setlength{\mathindent}{0pt}
  29. \allowdisplaybreaks
  30. \pagestyle{empty}
  31. \newcommand{\since}{\raisebox{0.56pt}{\rotatebox[origin=c]{180}{$\Large\wasytherefore$}}}
  32. \newcommand{\thus}{\Large\wasytherefore}
  33. \sisetup{inter-unit-product=\cdot,number-unit-product=\text{ },tight-spacing=true}
  34. \usepackage{calc}
  35.  
  36. \newcounter{custcount}
  37. \newenvironment{custenv}[5]{
  38. \setcounter{custcount}{1}
  39.  
  40. % Creates a single item in a tabular cell
  41. \newcommand{\custitem}[3]{
  42. \begin{minipage}[t]{\linewidth}
  43. \begin{enumerate}[##1, start=##2+\value{custcount}]
  44. \item ##3
  45. \end{enumerate}
  46. \end{minipage}}
  47.  
  48. % One line in the tabular
  49. \newcommand{\custline}[2]{
  50. \custitem{#2}{#3}{##1} & \custitem{#4}{#5}{##2}
  51. \addtocounter{custcount}{1}}
  52.  
  53. \tabular{#1}}
  54. {\endtabular}
  55.  
  56. \begin{document}
  57.  
  58. \begin{custenv}{@{}p{2in}p{2in}@{}} % first argument of custenv is the format of the tabular
  59. {a)}{0} % then, format of the left list
  60. {1)}{4} % and format fo the right list
  61. \custline{$\begin{array}[t]{@{}l@{}}
  62. \begin{aligned}[t]\ce{m_{\ce{He2}}}&=\text{4.2 mol}\times\text{4 g/mol} \\ &=\text{16.8 g}
  63. \end{aligned}\end{array}$}{bob}\\
  64. \custline{bob}{bob}
  65. \end{custenv}
  66.  
  67. \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

Postby ghostanime2001 » Mon Nov 07, 2011 11:13 pm

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)

  1. \documentclass{article}
  2. \usepackage[shortlabels]{enumitem}
  3. \usepackage{calc}
  4. \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}
  5. \begin{document}
  6. \begin{enumerate}[start=3]
  7. \item
  8. \begin{custenv}{@{}ll@{}}
  9. {a)}{0}
  10. {1)}{4}
  11. \custline{1}{2} \\
  12. \custline{3}{4} \\
  13. \custline{5}{6} \\
  14. \custline{7}{8}
  15. \end{custenv}
  16. \end{enumerate}
  17. \end{document}

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

Postby CDbile » Tue Nov 08, 2011 8:48 am

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

  1. \tabular[t]{#1}}{\endtabular}
CDbile

ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Postby ghostanime2001 » Tue Nov 08, 2011 9:03 am

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


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 7 guests