0

I'm trying to create a tabularx environment that will align a two column table table like in the picture, but I want the text on the right to wrap at a certain width.

What I've done: I've tried using w{align}{width} to set the alignment and the width. But here it seems that the "width" is the width of the cell itself, and doesn't care about the text inside of the cell. I've experimented in \newcolumntype which I think is where the answer lies, but I am having trouble understanding how it works. The 'declarations' don't make sense.

The behaviour I'm looking for is something like the p{#cm} while still being able to control alignment to the left. Would you help a LaTeX newbie out? :)

enter image description here

MWE:

\documentclass[tikz]{standalone}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tabularx}
\setlength{\tabcolsep}{3pt}
\renewcommand{\arraystretch}{0.3}

\begin{document}
\hspace{3cm}
\vspace{3cm}

\begin{tabularx}{\textwidth}{rl}
     \color{black}\textbf{\scalebox{0.5}{decision}} & \color{black}\textbf{\scalebox{0.5}{this is some text meant to be very long so I would have to wrap it.  It's a puzzling experience.}} \\
     \color{black}\textbf{\scalebox{0.5}{decisions, decisions}} & \color{black}\textbf{\scalebox{0.5}{this is some text meant to be very long so I would have to wrap it.  It's a puzzling experience.}} \\
     \color{black}\textbf{\scalebox{0.5}{decisions, decisions, decisions}} & \color{black}\textbf{\scalebox{0.5}{this is some text meant to be very long so I would have to wrap it.  It's a puzzling experience.}} \\
     \color{black}\textbf{\scalebox{0.5}{decision}} & \color{black}\textbf{\scalebox{0.5}{this is some text meant to be very long so I would have to wrap it.  It's a puzzling experience.}} \\
     \color{black}\textbf{\scalebox{0.5}{decision}} & \color{black}\textbf{\scalebox{0.5}{this is some text meant to be very long so I would have to wrap it.  It's a puzzling experience.}} \\
     \color{black}\textbf{\scalebox{0.5}{decision}} & \color{black}\textbf{\scalebox{0.5}{this is some text meant to be very long so I would have to wrap it.  It's a puzzling experience.}} \\
     \color{black}\textbf{\scalebox{0.5}{decision}} & \color{black}\textbf{\scalebox{0.5}{this is some text meant to be very long so I would have to wrap it.  It's a puzzling experience.}} \\
     \color{black}\textbf{\scalebox{0.5}{decision}} & \color{black}\textbf{\scalebox{0.5}{this is some text meant to be very long so I would have to wrap it.  It's a puzzling experience.}} \\
\end{tabularx}

\end{document}
6
  • 1
    Make the column on the right an X column, not l. You always need at least one X column with tabularx. – John Kormylo Jun 19 '20 at 13:15
  • What is the scalebox supposed to do here? – leandriis Jun 19 '20 at 13:22
  • X column extends it to the end of the page, right? will that fix the alignment issue? I've got two tables next to one another, one of them is leaking over into the other. @JohnKormylo – tblev Jun 19 '20 at 13:23
  • The scalebox is supposed to make the font tinier than \tiny but I enlarged it so it's easier to see on here. @leandriis – tblev Jun 19 '20 at 13:25
  • Tabularx adapts to the width you specify. In your example it is \textwidth but you can specify any width of your choice. Regarding the font size: tiny already is extremely small. A font size even smaller than that will be hardly readable. – leandriis Jun 19 '20 at 13:31
1

Like this?

\documentclass{article}
\usepackage{lmodern}
\usepackage{tabularx}
% smaller font size: https://tex.stackexchange.com/a/57676/201158
\newcolumntype{Y}{>{\raggedleft\arraybackslash\fontsize{2.5}{4}\selectfont}X}
\newcolumntype{P}[1]{>{\fontsize{4}{2}\selectfont}p{#1}}

\newcommand\test[1]{
  \noindent
  \begin{tabularx}{\linewidth}{YP{#1\linewidth}}
     decision & this is some text meant to be very long so I would have to wrap it.  It's a puzzling experience. \\
     decisions, decisions & this is some text meant to be very long so I would have to wrap it.  It's a puzzling experience. \\
     decisions, decisions, decisions & this is some text meant to be very long so I would have to wrap it.  It's a puzzling experience. \\
 \end{tabularx}\par\vspace{1em}
}

\begin{document}
\test{.8}
\test{.7}
\test{.6}
\end{document}

enter image description here

4
  • Hey, thank you for your answer. This is something along the lines of what I'm looking for. Although it doesn't seem to work with \scalebox. Anyway you could experiment with that? – tblev Jun 19 '20 at 13:57
  • Do you really need to use a \scalebox? – ZhiyuanLck Jun 19 '20 at 13:58
  • Well I want the text to be smaller than tiny. That's just what I've been using to do it. – tblev Jun 19 '20 at 13:59
  • Yeah scalebox was really getting in the way. I found the \fontsize thing but your preamble new command is very helpful. Much appreciated. – tblev Jun 19 '20 at 14:12

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.