1

I have a formula which has a content like below..

\documentclass[journal]{IEEEtran}
\usepackage[backend=biber]{biblatex}
\addbibresource{bibliography.bib} %Import the bibliography file
\usepackage{lipsum}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{graphicx}
\usepackage{adjustbox}
\hyphenation{op-tical net-works semi-conduc-tor}
\usepackage{amsmath,amssymb}

\DeclareRobustCommand{\bbone}{\text{\usefont{U}{bbold}{m}{n}1}}

\DeclareMathOperator{\EX}{\mathbb{E}}

\DeclareMathOperator{\E}{\mathbb{E}} \begin{document} \maketitle \lipsum

\begin{equation} \begin{aligned}[c] reward(node, action) = \begin{cases} constant_action_reward -\par action_cost + success_prob(action, sequence) * node_reward,& \text{if } "XXX"=action constant_action_taking_reward - action_cost, & \text{otherwise} \end{cases} \end{aligned} \end{equation}

\lipsum

\end{document}

I tried this both in double column using the * like {equation*} and not. Paper is double column. In each option, this covers a two column and other text comes over this. I attached a sample picture. I would be happy if it fits a single column or at least it covers a double column and no text comes over it.

enter image description here

Imran
  • 3,096
  • 2
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Imran Jul 27 '22 at 16:40
  • 1
    For sure, you should tell us which document class you employ, which font families are used (unless they're the document class' default), and which main font size you use. – Mico Jul 27 '22 at 17:06
  • What's the purpose of using an aligned environment? – Mico Jul 27 '22 at 17:07
  • unrelated but use \mathrm{constant\_action\_reward} (or \mathit) never use the math italic font for multi-letter words, it makes adjacent letters look like a product of 1-letter variables – David Carlisle Jul 27 '22 at 17:12
  • For ieeetran, its user manual describes how to do double-column equations (it is a bit unwieldy) by using floats on or around page 12. See also this previous question. // Incidentally, the code you showed is also missing a line break after "xxx"=action. And I an not sure what \par is doing in the middle of the equation. The code you provided as stands cannot be compiled. – Willie Wong Jul 27 '22 at 18:48
  • 1
    Your equation is longer than \textwidth. Even if you write across both columns, it will not fit on the page. To my opinion the best is rephrase this part of your article and avoid to use equation. – Zarko Jul 27 '22 at 18:56
  • However, you can try to write long terms in several lines, for example as = \begin{cases} \begin{aligned} & \mathit{constant\_action\_reward} - \\[-1ex] & \mathit{action\_cost} + \mathit{success\_prob(action, sequence)}* \\[-1ex] & \mathit{node\_reward} \end{aligned}. But even with this trick equation is to long. So the next try is to define abbreviations for your text in equation. – Zarko Jul 27 '22 at 18:57

2 Answers2

1

As Zarko commented your equation wouldn't fit even if you use double-column.

The first option, which I think is the best, is to use shorter variable names.

If you must use the formula exactly as it appears, Zarko suggested you break the first line of the cases. I think it looks better instead of you break before the cases. (And you should display this with the full text width: in one column using the variable names as they stand there is no way to display your equation in fewer than 5 lines, which makes it not very legible.)

\documentclass[journal]{IEEEtran}
\usepackage[backend=biber]{biblatex}
\addbibresource{bibliography.bib} %Import the bibliography file
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{adjustbox}
\hyphenation{op-tical net-works semi-conduc-tor}
\usepackage{amsmath,amssymb}

\begin{document} \lipsum

\begin{equation} E = mc^2 \end{equation}

\begin{figure}[!t] \normalsize \begin{multline} \mathsf{reward(node, action)} = \ \begin{cases} \mathsf{constant_action_reward} - \mathsf{action_cost} + \mathsf{success_prob(action, sequence)} \mathsf{node_reward},& \text{if ``XXX''=action} \ \mathsf{constant_action_taking_reward} - \mathsf{action_cost}, & \text{otherwise} \end{cases} \end{multline} \hrulefill % The spacer can be tweaked to stop underfull vboxes. \vspace{4pt} \end{figure}

\begin{equation} E = mc^e \end{equation}

\lipsum \end{document}

Some notes:

  1. I wrapped your variable names in \mathsf since they look like computer variable names. If they were words I would use \mathrm or \mathit as David Carlisle suggested.
  2. There are some other small mistakes in the displayed equation that I fixed.
  3. I have no idea what the semantic meaning of "XXX"=action is, so I left them as text. But you should adjust to fit the meaning.
  4. If you compile this document, you will see that the the equation is numbered out of order. This is "by design": the IEEEtran documentation indicates a preference for double-column equations to be floated to the top of the next page. The code included in the documentation provides a way to restore the correct numbering; but this requires manual intervention and should be set AFTER you finished your entire document. So I omit that in the code above.
Willie Wong
  • 24,733
  • 8
  • 74
  • 106
1

First of all you should use a Times compatible font also for math and also wrap your long names in \mathit or similar.

Second, you need to split the long top line. Using cases is out of the question, I'm afraid.

A bit of visual formatting helps.

\documentclass[journal]{IEEEtran}
\usepackage{amsmath,mathtools,amssymb}
\usepackage{newtx} % for math symbol compatible with Times

\usepackage{lipsum}

\newcommand{\tv}[1]{\mathit{#1}} % text variable

\begin{document}

\lipsum[1][1-4] \begin{equation} \hspace{-0.5em} \begin{aligned} &\tv{reward}(\tv{node}, \tv{action}) \ & = \left{ \begin{aligned} &\begin{aligned} \begin{aligned} &\tv{constant_action_reward} - \tv{action_cost} \ &+ \tv{success_prob}(\tv{action}, \tv{sequence}) \cdot \tv{node_reward}, \end{aligned} \ \text{if } \text{"XXX"}=\tv{action}\hspace{-0.3em} \end{aligned} \[2ex] &\begin{aligned} \tv{constant_action_taking_reward} - \tv{action_cost}, \ \text{otherwise}\hspace{-1em} \end{aligned} \end{aligned}\right. \end{aligned} \hspace{1000pt minus 1fil} \end{equation} \lipsum

\end{document}

enter image description here

egreg
  • 1,121,712