4

I want to make equation (1) more compact with the equation id in the same line. Currently, it looks like this.

enter image description here

\documentclass[10pt, oneside, twocolumn, notitlepage]{book}
\usepackage{amsthm,latexsym,amssymb,amsmath, amsfonts}
\usepackage{graphicx}
\usepackage{lipsum}

\newtheorem{thm}{Theorem}[section]


\newtheorem{rem}[thm]{Remark}

\begin{document}
\lipsum[1]
%\resizebox{.9\linewidth}{!}{
\begin{align} 
\label{eq:LS1}
    \mathbf{u}_{e}^{b} = \tanh\Big(\sum_{(r,e') \in \mathcal{N}_{\operatorname{in}}(e)} \mathbf{W}_{\operatorname{in}}\mathbf{z}_{r} +\sum_{(r, e') \in \mathcal{N}_{\operatorname{out}}(e)} \mathbf{W}_{\operatorname{out}} \mathbf{z}_r\Big),
\end{align}%}Z
\lipsum
\end{document}

I tried using \mathclap to delete the space around \sum but it looks a little ugly (too tight).

enter image description here

Is there a way to reduce the space around \sum by a little bit, but not delete all?

3
  • Welcome to TeX.SE.
    – Mico
    Jan 4, 2022 at 6:09
  • Off-topic: \operatorname{in} and \operatorname{out} is simply wrong; it should be \mathrm{in} and \mathrm{out}, respectively.
    – Mico
    Jan 4, 2022 at 6:10
  • @Mico Thank you!
    – Mojie11
    Jan 4, 2022 at 6:16

4 Answers 4

6

The following example defines \makemathbox[<width>]{<math>} as a math-equivalent to \makebox[<width>]{<stuff>}. You can specify a proportional \width to set the \sum subscript over a smaller portion of its natural width.

enter image description here

\documentclass[twocolumn]{book}

\usepackage{amsmath}
\usepackage{lipsum}

\makeatletter
\NewDocumentCommand{\makemathbox}{O{\width} m}{%
  \def\makemathbox@##1##2{\makebox[#1]{$##1##2$}}%
  \mathpalette\makemathbox@{#2}%
}
\makeatother

\begin{document}

\lipsum[1]
\begin{equation} 
  \mathbf{u}_e^b = \tanh\Big(
    \sum_{\makemathbox[.5\width]{(r,e') \in \mathcal{N}_{\mathrm{in}}(e)}} \mathbf{W}_{\mathrm{in}}\mathbf{z}_r + 
      \sum_{\makemathbox[.5\width]{(r, e') \in \mathcal{N}_{\mathrm{out}}(e)}} \mathbf{W}_{\mathrm{out}} \mathbf{z}_r
    \Big),
\end{equation}
\lipsum

\end{document}

An example using varied widths:

enter image description here

\usepackage{array}
%...
\[
  \begin{array}{ c >{\displaystyle}c }
    \verb|1.0\width| & \left| \sum_{(r,e') \in \mathcal{N}_{\mathrm{in}}(e)} \right| \\
    \verb|0.9\width| & \left| \sum_{\makemathbox[0.9\width]{(r,e') \in \mathcal{N}_{\mathrm{in}}(e)}} \right| \\
    \verb|0.8\width| & \left| \sum_{\makemathbox[0.8\width]{(r,e') \in \mathcal{N}_{\mathrm{in}}(e)}} \right| \\
    \verb|0.7\width| & \left| \sum_{\makemathbox[0.7\width]{(r,e') \in \mathcal{N}_{\mathrm{in}}(e)}} \right| \\
    \verb|0.6\width| & \left| \sum_{\makemathbox[0.6\width]{(r,e') \in \mathcal{N}_{\mathrm{in}}(e)}} \right| \\
    \verb|0.5\width| & \left| \sum_{\makemathbox[0.5\width]{(r,e') \in \mathcal{N}_{\mathrm{in}}(e)}} \right| \\
    \verb|0.4\width| & \left| \sum_{\makemathbox[0.4\width]{(r,e') \in \mathcal{N}_{\mathrm{in}}(e)}} \right| \\
    \verb|0.3\width| & \left| \sum_{\makemathbox[0.3\width]{(r,e') \in \mathcal{N}_{\mathrm{in}}(e)}} \right| \\
    \verb|0.2\width| & \left| \sum_{\makemathbox[0.2\width]{(r,e') \in \mathcal{N}_{\mathrm{in}}(e)}} \right| \\
    \verb|0.1\width| & \left| \sum_{\makemathbox[0.1\width]{(r,e') \in \mathcal{N}_{\mathrm{in}}(e)}} \right| \\
    \verb|0.0\width| & \left| \sum_{\makemathbox[0.0\width]{(r,e') \in \mathcal{N}_{\mathrm{in}}(e)}} \right|
  \end{array}
\]
1
  • This solves my problem! Thank you.
    – Mojie11
    Jan 4, 2022 at 6:40
2

Typesetting large formulas in two-column format often requires some compromise.

I suggest to explain after the formula where the indices are taken from.

\documentclass[10pt, oneside, twocolumn, notitlepage]{book}
\usepackage{amsthm,amssymb,amsmath}

\usepackage{lipsum}

\begin{document}

\lipsum[1][1-3]
\begin{equation}\label{eq:LS1}
  \mathbf{u}_{e}^{b} =
  \tanh\Bigl(
    \sum_{\mathrm{in}} \mathbf{W}_{\mathrm{in}}\mathbf{z}_{r}
    +
    \sum_{\mathrm{out}} \mathbf{W}_{\mathrm{out}} \mathbf{z}_r
  \Bigr),
\end{equation}
where the first summation is taken for
$(r,e') \in \mathcal{N}_{\mathrm{in}}(e)$ and the second for
$(r, e') \in \mathcal{N}_{\mathrm{out}}(e)$.

\lipsum

\end{document}

A few points to note:

  1. don't load latexsym along with amssymb;
  2. amsfonts is already loaded by amsfonts;
  3. don't use \operatorname for getting upright letters, unless you really have an operator (which is not the case here);
  4. don't use align when there's only one line.

enter image description here

1

Having to make trade-offs is almost inevitable in fine typography. The key is to minimize the total "cost" of the trade-offs.

Since typesetting the equation and its associated equation number on a single line is very important, compromises will have to be made elsewhere. IMNSHOm, any negative side effects of using \mathclap (or, equivalently, \smashoperator) on the two summation expressions may be countered, for the most part, by replacing \Big( and Big) with \bigl( and \bigr, respectively.

To further improve the appearance of the formula and the quality of the underlying code, consider (a) throwing in a few \! (negative thin space) directives in order to improve the kerning and (b) replacing the \operatorname directives with \mathrm directives.

enter image description here

\documentclass[oneside, twocolumn]{book}
\usepackage{mathtools,lipsum}

\begin{document}
\hrule % illustrate width of text (column) block
\begin{gather} 
  \mathbf{u}_{e}^{b} = \tanh\Big(
  \sum_{(r,e') \in \mathcal{N}_{\operatorname{in}}(e)}  
  \mathbf{W}_{\operatorname{in}}  \mathbf{z}_{r} 
 +\sum_{(r, e') \in \mathcal{N}_{\operatorname{out}}(e)}
  \mathbf{W}_{\operatorname{out}} \mathbf{z}_{r}
  \Big), 
  \\[1ex]
  \mathbf{u}_{e}^{b} = \tanh\bigl(\,
  \smashoperator{\sum_{(r,e')  \in \mathcal{N}_{\mathrm{in}}\mkern-1.5mu(e)}}   
  \mathbf{W}_{\!\mathrm{in}}  \mathbf{z}_{r} 
 +\smashoperator{\sum_{(r, e') \in \mathcal{N}_{\mathrm{out}}\mkern-1.5mu(e)}} 
  \mathbf{W}_{\!\mathrm{out}} \mathbf{z}_{r}
  \bigr),
\end{gather}
\hrule
\end{document}
1
  • Thanks for your tips. I used the command \makemathbox[<width>]{<math>} in @Werner 's answer and the problem get solved.
    – Mojie11
    Jan 4, 2022 at 6:44
1

The mathtools package (which loads amsmath) defines a\smashoperator command which does the job.

Unrelated: needless to load amsfonts when you load amssymb: the latter does it for you.

\documentclass[10pt, oneside, twocolumn, notitlepage]{book}
\usepackage{amsthm, amssymb,mathtools}
\usepackage{graphicx}
\usepackage{lipsum}

\begin{document}

\lipsum[1]
\begin{align}
\label{eq:LS1}
    \mathbf{u}_{e}^{b} = \tanh\Bigl(\smashoperator{\sum_{(r,e') \in \mathcal{N}_{\operatorname{in}}(e)}} \mathbf{W}_{\operatorname{in}}\mathbf{z}_{r} +\smashoperator{\sum_{(r, e') \in \mathcal{N}_{\operatorname{out}}(e)}} \mathbf{W}_{\operatorname{out}} \mathbf{z}_r\Bigr),
\end{align}

\lipsum

\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .