1

How can I draw 2 separated lines in the same line, and write centered text below them?

I tried with this code

\begin{flushleft}
\rule{7cm}{.01cm}

Name 1 \end{flushleft}

\hspace{1cm}

\begin{flushright} \rule{7cm}{.01cm} Name 2 \end{flushright}

But the output was incorrect because

  1. The lines were drawn in separated lines (and there was enough space to be drawn both in the same line)

  2. The text below them wasn't centered but moved to the left and right, respectively

Can someone please help?

Thanks in advance

1 Answers1

2

I'm not sure I understand 100% what you're trying to achieve, but --- like this?

\documentclass{article}
\begin{document}
\begin{center}
\rule{0.4\textwidth}{1pt} \hfill \rule{0.4\textwidth}{1pt} \\
Text
\end{center}
\end{document}

enter image description here

This is what comes to my mind when I hear "two separated lines in the same line, and centered text below them" anyway.

EDIT:

Here's what I might do in order to put centered text under each line:

\documentclass{article}
\usepackage{tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{Yp{1cm}Y}
\cline{1-1} \cline{3-3}
Text 1 && Text 2
\end{tabularx}
\end{document}

(The Y column type is taken from @Huugo's answer here.) Using \cline is probably suboptimal, and I'm sure there's more elegant, better-looking or just plain simpler ways of achieving this; I'm no TeXnician yet! But it might get you started.

enter image description here

EDIT 2:

Here's another version that uses \hrulefill (which I hadn't known about until now!) instead of \cline, and adds a little space between the two lines of the tabular environment by supplying the \\'s optional parameter --- one ex, to be precise, adjust this to your liking.

Speaking of spaces, the gap between the two lines is currently set to one centimeter, and this can also be adjusted. What's more, if you want to make the whole tabular narrower, you can change its width from \textwidth to 0.8\textwidth or something along those lines. (You'll probably want to wrap it in a center environment again then, otherwise it'll be flush left.)

\documentclass{article}
\usepackage{tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{Yp{1cm}Y}
\hrulefill&&\hrulefill\\[1ex]
Text 1 && Text 2
\end{tabularx}
\end{document}

enter image description here

Hope this helps!

chsk
  • 3,667
  • Something like that, tho the text goes below the lines: text 1, text 2 – Verónica Rmz. Apr 07 '21 at 15:39
  • Ah, I see. Give me a moment. – chsk Apr 07 '21 at 15:44
  • @Verónica how's this now? – chsk Apr 07 '21 at 15:47
  • Aha, that was the idea. Although with more space between the line and the text. Like if using \begin{center} \rule{7cm}{.01cm} name \end{center} – Verónica Rmz. Apr 07 '21 at 16:07
  • @Verónica I made another edit --- see if this is what you need now! – chsk Apr 07 '21 at 18:16
  • Thank you. I tried this. For some reason the parameter [1ex] of \ doesn't work to be reduced. Works to be expanded, I tried with 5 and separated the text from the line. I tried with .001ex but does nothing, it's like if it had 1ex. Also, doesn't match with the image that you display, that space is smaller than the one that I see. – Verónica Rmz. Apr 07 '21 at 18:56
  • @Verónica [1ex] means that one ex of extra space gets added. 0.001ex is going to be about the same as nothing at all, i.e. \\ without the optional parameter. You can pass negative values though, so perhaps try \\[-1ex] and go from there. – chsk Apr 07 '21 at 18:59
  • ahhh. Got it, it worked :) thanks again. – Verónica Rmz. Apr 07 '21 at 19:05
  • 1
    You're welcome! :) – chsk Apr 07 '21 at 19:33