2

How could I vertically move the third line on the left upward so that it doesn't appear broken with the two lines above?

enter image description here

I'd like to obtain this.

enter image description here

I have used this code.

\documentclass{article}

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex \nobreak\hfill\penalty50\quad\hbox{}\hfill
$\left[\displaystyle{\frac{\frac{1}{2}}{3+4}}\right]$ \finalhyphendemerits=0 \parfillskip=0pt \par

\end{document}
2
  • Hi and welcome to TeX.SE! If the paragraph is followed by another paragraph, how do you want it to look? (My suggestion is to avoid that tall formulas in inline text. In the example you show, you could for example slash the fraction.)
    – mickep
    Mar 25 at 16:39
  • I really need to write things like that, so I can't avoid it. I changed pictures to show how next paragraph should look.
    – Sempry
    Mar 25 at 16:56

4 Answers 4

3

First of all, your setting of \finalhyphendemerits and \parfillskip are wrong, because they propagate to the following paragraphs. You need to enclose them in a group.

Clearly, a macro is advisable.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\solution}[1]{%
  \unskip\nobreak
  \hfill\penalty50\quad\hbox{}\hfill
  \raisebox{\dimexpr\fontcharht\font`T-\height}{$\left[#1\right]$}%
  {\finalhyphendemerits=0 \parfillskip=0pt \par}%
  \prevdepth=\fontchardp\font`y
}

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor 
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis 
nostrud exercitation ullamco laboris nisi ut aliquip ex
\solution{\dfrac{\frac{1}{2}}{3+4}}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor 
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis 
nostrud exercitation ullamco laboris nisi ut aliquip ex

\end{document}

I first raise down the object by its height, then raise it by the height of a capital letter. Finally, I set the \prevdepth to the depth of a letter with a descender so as to cover our tracks.

enter image description here

1
  • Thank you, prof!
    – Sempry
    Mar 27 at 20:50
4

A solution with \raisebox, and a simplification of your code;

    \documentclass{article}

    \begin{document}

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex \nobreak\hfill\penalty50\quad\hbox{}\hfill
    \raisebox{-0.5\baselineskip}{$\left[\displaystyle{\frac{\frac{1}{2}}{3+4}}\right]$}%

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex

    \end{document} 

enter image description here

2
  • I would use {\dimexpr \ht\strutbox-\height} to precisely place the baseline one line down. Mar 25 at 21:02
  • @JohnKormylo: you're right – I just used trial and error to write the code faster.
    – Bernard
    Mar 25 at 21:19
2

I'm not sure if this is exactly what you want, but here is a macro \fright that puts the expression into a minipage that has the width of the given expression. The minipage is top-aligned and shifted up by the height of a ( character.

enter image description here

\documentclass{article}

\newlength{\chrht}
\settoheight{\chrht}{(}
\newlength{\wdth}

\newcommand{\fright}[1]{\settowidth{\wdth}{#1}\begin{minipage}[t]{\wdth}\vspace{-\chrht}#1\end{minipage}}

\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex \hfill
\fright{$\left[\displaystyle{\frac{\frac{1}{2}}{3+4}}\right]$}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex.
\end{document}
2

You can raisebox that math expression as the negative difference between normal height and its height.

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\makeatletter
\newcommand{\noht}[1]{\raisebox{\dimexpr-\height+\f@size pt}{#1}}
\makeatother

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex \nobreak\hfill\penalty50\quad\hbox{}\hfill
\noht{$\left[\dfrac{\frac12}{3+4}\right]$} \finalhyphendemerits=0 \parfillskip=0pt

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex \nobreak\hfill\penalty50\quad\hbox{}\hfill

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.