1

I was looking for an example here about setting the lengh of the command \underline. I'm trying to produce a text on top of a line with 10cm fixed length, with text of variable size. In addition the text should be left aligned (not centered as the examples founded here produce) Here's a minimal example. Thank you.

\documentclass[a4paper,brazil, 12pt]{report}
\usepackage{amsmath,amsfonts,amscd,bezier}
\usepackage{amssymb}
\usepackage{babel}
\usepackage[latin1]{inputenc}
\usepackage[shortlabels]{enumitem}
\usepackage{multicol}
\usepackage{tasks}
\usepackage{tikz, tkz-euclide}

%%https://tex.stackexchange.com/questions/334787/constant-length-of-underline

\usepackage{eqparbox, ulem}
\newcommand\ulmakebox[2][ULB]{\eqsetminwidth{#1}{10cm}\underline{\eqmakebox[#1]{#2}}}

\newcommand{\wideunderline}[2][2em]{%
    \underline{\makebox[\ifdim\width>#1\width\else#1\fi]{#2}}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\begin{document}

\begin{minipage}{5cm}
    \noindent (line 1) $\mathbf{u+w=v+w},$

    \noindent (line 2) $\mathbf{u+w=v+w},$

    \noindent (line 3)  $\mathbf{u+w=v+w},$

    \noindent (line 4)  $\mathbf{u+w=v+w},$

    \noindent (line 5)  $\mathbf{u+w=v+w},$

    \noindent (line 6)  $\mathbf{u+w=v+w},$
\end{minipage}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\hspace*{4.4cm}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{minipage}{10cm}

    \underline{text here (in front of line 1) \hspace{4cm}}

    \underline{more text here (in front of line 2) \hspace{3cm}}

    \noindent \ulmakebox{\noindent(in front of line 3)}

    \wideunderline[10cm]{\noindent text here (in front of line 4)}

    \begin{tikzpicture} %\without text line in front of line 5
    \draw (0,0) to (10,0);
    \end{tikzpicture}

    \begin{tikzpicture} %\without text line in front of line 6
    \draw (0,0) to (10,0);
    \end{tikzpicture}
\end{minipage}

\end{document}
Moura
  • 1,555
  • 1
    In the linked question there is a comment about left alignment (https://tex.stackexchange.com/questions/334787/constant-length-of-underline?noredirect=1&lq=1#comment820800_334788), maybe that can help you? – Marijn Apr 02 '19 at 21:02

1 Answers1

3

Not sure what's the problem. Use the [l] option for \makebox.

\documentclass{article}

\usepackage{ulem}

\newcommand{\wideunderline}[2][2em]{%
  \uline{\makebox[\ifdim\width>#1\width\else#1\fi][l]{#2}}%
}

\begin{document}

(line 1) \wideunderline[10cm]{text here}

(line 2) \wideunderline[10cm]{text here with a p}

\end{document}

enter image description here

egreg
  • 1,121,712