LaTeX forum ⇒ Math & ScienceEquations on two columns Topic is solved

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Re: Equations on two columns

Postby Cham » Sat Jan 17, 2015 9:22 pm

Can't we use centering tabs in LaTeX ?

I'm already using the tabto package, just for some very specific usages. But apparently, I can use it just to push things to the right, not to center items, and I'm not sure its working with equations.

Tags:

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sat Jan 17, 2015 10:41 pm

Oh my God, is that possible ? I may have found a trivial solution using the mathclap command :

  1. \documentclass[12pt,letterpaper]{book}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{mathtools}
  4. \usepackage{showframe}
  5. \usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
  6.  
  7. \begin{document}
  8. \begin{align}
  9. &\mathclap{x = y^2 - c + d + z^3,}
  10. &&\mathclap{z = x^3 + x - y^2.}
  11. \end{align}
  12. Just another small line of text :
  13. \begin{align}
  14. &\mathclap{x -5 y + 3 = y^2,}
  15. &&\mathclap{y^2 = -\: x^2 + 4 - y^2 - x.}
  16. \end{align}
  17. Yet another line :
  18. \begin{align}
  19. &\mathclap{A + B + E = b,}
  20. &&\mathclap{B - C = 0.}
  21. \end{align}
  22. The global distribution of these equations is less ugly !
  23.  
  24. \end{document}


Here's a preview of a more complex document, using mathclap inside the align environment. The equations are centered around the blue lines, approximately. Take note that the point "." and the comma "," must be included inside the mathclap directive.

centering.jpg
centering.jpg (112.05 KiB) Viewed 2953 times


What do you think ?

Any problem with this, that I can't see for the moment ?

And what about the spacing between the blue lines ? Can it be adjusted ?

User avatar
Johannes_B
Site Moderator
Posts: 3854
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Sun Jan 18, 2015 4:17 pm

http://chat.stackexchange.com/transcrip ... 2#19534572

You didn't follow the discussion that was trying to solve your your problem? :-(


\mathclap puts its content in a box of zero width and centers it. Was my very first test, but it fails when an equation is very long. So once again, this is a manual thing.

Why is there no package for that? Apparently, no one had need for it so far. I suggest to reach to the maintainers via mail and present the problem as well as the motivation for doing so. They may know more about alternatives. Don't forget to link this discussion, they might be interested in what was discussed and presented so far.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sun Jan 18, 2015 4:44 pm

Johannes_B wrote:\mathclap puts its content in a box of zero width and centers it. Was my very first test, but it fails when an equation is very long. So once again, this is a manual thing.


In what way does it fail ?

I guess that a long equation could overlap on the second one, but then you may get the same with any double equations styles.

If an equation is very long, I wouldn't put it in a double equation line anyway.
Double equations aren't intended for long equations.

How could we define a new environment, using the solution I'm proposing ?

User avatar
Johannes_B
Site Moderator
Posts: 3854
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Sun Jan 18, 2015 5:48 pm

  1. \documentclass[12pt,letterpaper]{book}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{mathtools}
  4. \usepackage{showframe}
  5. \usepackage{tabularx}
  6. \usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
  7. \newcommand{\dbleq}[2]{\begin{align}&\mathclap{#1}&&\mathclap{#2}\end{align}}
  8. \begin{document}
  9. \dbleq{x = y^2 - c + d + 12b + 17 c - 4f -(x^r)^2 z^3,}{y^2 = -\: x^2 + 4 - y^2 - x.}
  10.  
  11. Just another small line of text :
  12. \dbleq{x -5 y + 3 = y^2,}{y^2 = -\: x^2 + 4 - y^2 - x.}
  13. \end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sun Jan 18, 2015 6:14 pm

Hehe !

It's evident that I wouldn"t present the first two equations in a double-equs line.

Like I said in my first message (on page 1), the double-equs line is used just for two small equations.

Thanks a lot for the macro. Should be usefull.

EDIT : But then, how do you add a label to a double-equs., using your macro ?

EDIT 2 : I guess we need to modify the macro like this (is that the right way to do it, for an optional label ?) :

  1. \newcommand{\dbleq}[3]{\begin{align}&\mathclap{#1}&&\mathclap{#2}{#3}\end{align}}


I suspect that for an optional label, the command should be like \dbleq[label]{eq1}{eq1}

User avatar
Johannes_B
Site Moderator
Posts: 3854
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Sun Jan 18, 2015 6:46 pm

No, you don't you can just type in the label in the second argument. Look at it, it is exaclty the same that you came up with.

If you want to have an extra argument just for the label, you could also define an optional argument. With package xparse you can save even more time. And after all, LaTeX is a macro language.

  1. \documentclass[12pt,letterpaper]{book}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{mathtools}
  4. \usepackage{showframe}
  5. \usepackage{tabularx}
  6. \usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
  7. \newcommand{\dbleq}[3][]{\begin{align}&\mathclap{#2}&&\mathclap{#3}#1\end{align}}
  8.  
  9. \usepackage{xparse}
  10. \NewDocumentCommand{\dblq}{ m m o }{%
  11. \begin{align}&\mathclap{#1}&&\mathclap{#2}\IfNoValueTF{#3}{}{\label{eq:#3}}\end{align}}
  12.  
  13. \begin{document}
  14. \dbleq{x = y^2 - c + d + 12b + 17 c - 4f -(x^r)^2 z^3,}{y^2 = -\: x^2 + 4 - y^2 - x.}
  15.  
  16. Just another small line of text :
  17. \dbleq[\label{eq:cham}]{x -5 y + 3 = y^2,}{y^2 = -\: x^2 + 4 - y^2 - x.}
  18. can we refer to \eqref{eq:cham} and \eqref{eq:chamA}?
  19.  
  20. \dblq{x -5 y + 3 = y^2,}{y^2 = -\: x^2 + 4 - y^2 - x.}[chamA]
  21. \end{document}


DISCLAIMER: Macros for saving typing time are bad, especially when math is involved. This might break sooner than you wish.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sun Jan 18, 2015 6:58 pm

Johannes_B wrote:No, you don't you can just type in the label in the second argument. Look at it, it is exaclty the same that you came up with.


I tried with the label inside the second argument, and got an error.

User avatar
Johannes_B
Site Moderator
Posts: 3854
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Sun Jan 18, 2015 7:09 pm

Ah, right, sorry. My mistake.

Mathtools typesets its argument 4 times in different styles and applies only once. Hence you get the error of defining the same label multiple times.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sun Jan 18, 2015 7:22 pm

I think I like pretty much this solution :

  1. \newcommand{\dbleq}[3][]{\begin{align}&\mathclap{#2}&&\mathclap{#3}\label{#1}\end{align}}


This way, you don't need to type \label{}, since it's already defined as an optional argument just for the label. And the code is then easier to read and to understand (I think).

The spacement could be adjusted easily :

  1. \newcommand{\dbleq}[3][]{\begin{align}&\mathclap{#2}\quad&&\quad\mathclap{#3}\label{#1}\end{align}}


According to the quick test I just made, this is working great, even with large equation numbers :
2equs_test.jpg
2equs_test.jpg (53.78 KiB) Viewed 2932 times


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 5 guests