1

I'm not sure why the text isn't wrapping in this code

\documentclass{article}

\usepackage{tabularx}
\usepackage{multirow, multicol}
\usepackage{array}

% column vertical space buffer in tables
\def\arraystretch{2}

% \maketable{number of columns}{table data}
\newcommand{\maketable}[2]{
    \centering
    \begin{tabularx}{\textwidth}{
        % paste |>{\raggedright\arraybackslash}X
        % #1 number of times. Finally, append a |
        % to add the right wall of table
        *{#1}{|>{\raggedright\arraybackslash}X}|
    } 
        \hline
        #2
        \hline
    \end{tabularx}
}

\newcommand{\mergecols}[2]{\multicolumn{#1}{|l|}{#2}\\\hline}

\begin{document}
\maketable{3}{
    \mergecols{3}{\textbf{Title}: Affect of Color Filtered Light on Photosynthesis and Oxygen Production}

    \mergecols{3}{\textbf{Hypothesis}: Stuff About Project}

    \mergecols{3}{\textbf{Experimental Units}: Freshwater Algae Suspended in Sodium Alginate Beads}

    \mergecols{3}{\textbf{Randomization}: The Algae Beads will be Randomly Assigned to a Specific Color Filter}

    \mergecols{3}{\textbf{Independent Variable (IV)}: The color of the light filter placed on the algae beads}

    \textbf{Treatment Groups:} & 2 & 3\\ \hline
    \textbf{Independent Trials} & 2 & 3\\ \hline

    \mergecols{3}{\textbf{Dependant Variable (DV)}: The rate of photosynthesis/the amount of oxygen found in the samples}

    \mergecols{3}{\textbf{Constants}: Stuff About Project}
}
\end{document}

I looked at this and this question, but I couldn't get it to work and would appreciate any help.

5
  • 1
    almost all of the text is in a multicolumn{3}{l} and l entries are single line. Dec 2, 2023 at 20:27
  • 1
    why are those lines in the table at all, shouldn't they simply be paragraphs before and after the table? Dec 2, 2023 at 20:28
  • 1
    beware your \maketable does not group its declarations so will make the entire documente centered. Dec 2, 2023 at 20:30
  • Unfortunately, this is for an assignment where it has to be in this format. What should I use instead of l in multicolumn? Dec 14, 2023 at 23:05
  • it makes no sense to have a requirement to have syntax errors, try replacing l by p{3cm} for whatever length you like Dec 14, 2023 at 23:11

2 Answers 2

1
  • By use of tabularray package is fairly simpler to write your table (see the first part of MWE below) directly in table, without of use.
  • However more "professional" look of your table is shown in nice @Mico answer (+1). Small variation of it is given in the second part of MWE below:
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
\noindent\begin{tblr}{hlines, vlines,
                      colspec = { *{3}{X[l]} },
                      cell{1-5,8,9}{1} = {c=3}{},
                      hspan = minimal,
                      }
\textbf{Title}: Affect of Color Filtered Light on Photosynthesis and Oxygen Production
    &   &   \\
\textbf{Hypothesis}: Stuff About Project 
    &   &   \\
\textbf{Experimental Units}: Freshwater Algae Suspended in Sodium Alginate Beads
    &   &   \\
\textbf{Randomization}: The Algae Beads will be Randomly Assigned to a Specific Color Filter
    &   &   \\
\textbf{Independent Variable (IV)}: The color of the light filter placed on the algae beads
    &   &   \\
\textbf{Treatment Groups:} 
    & 2 & 3 \\ 
\textbf{Independent Trials} 
    & 2 & 3 \\
\textbf{Dependant Variable (DV)}: The rate of photosynthesis/the amount of oxygen found in the samples
    & 2 & 3 \\
\textbf{Constants}: Stuff About Project
    & 2 & 3 \\
    \end{tblr}
    
\bigskip

\noindent\begin{tblr}{colspec = {@{} X[r, font=\bfseries] *{2}{X[l]} @{}},
                      cell{1-5,8,9}{2} = {c=2}{},
                      rowsep  = 3pt,
                      hspan   = minimal,
                      }
    \toprule
Title:  &   Affect of Color Filtered Light on Photosynthesis and Oxygen Production
            &       \\
Hypothesis:
        &   Stuff About Project
            &       \\
Experimental Units:
        &   Freshwater Algae Suspended in Sodium Alginate Beads
            &       \\
Randomization:
        &   The Algae Beads will be Randomly Assigned to a Specific Color Filter
            &       \\
Independent Variable (IV):
        &   The color of the light filter placed on the algae beads
            &       \\
    \midrule
Treatment Groups:
        & 2 & 3     \\
Independent Trials:
        & 2 & 3     \\
    \midrule
Dependant Variable (DV):
        &   The rate of photosynthesis/the amount of oxygen found in the samples
            &       \\
Constants:
        &   Stuff About Project
            &       \\
    \bottomrule
    \end{tblr}
\end{document}

enter image description here

1

Is the following maybe somewhat close to what you're trying to get done?

Observe that I wouldn't bold-face the material in the first column. If, however, you believe that bold-facing is essential, just change the first L in the final argument of tabularx to >{\bfseries}L.

enter image description here

\documentclass{article}
\usepackage{tabularx} % for 'tabularx' env. and 'X' col. type
\usepackage{ragged2e} % for '\RaggedRight' macro
\usepackage{booktabs} % for well-spaced horizontal rules
\newcolumntype{L}{>{\RaggedRight}X} % suppress full justification
% handy shortcut macro (for combing columns 2 and 3):
\newcommand\mC[1]{\multicolumn{2}{%
   >{\hsize=\dimexpr2\hsize+2\tabcolsep\relax}L}{#1}}
\setlength\extrarowheight{3pt} % for a more open "look"

\begin{document}

\noindent
\begin{tabularx}{\textwidth}{@{} LLL @{}}
\toprule
Title              & \mC{Effect of color filtered light on photosynthesis and oxygen production} \\
Hypothesis         & \mC{Stuff about project} \\
Experimental units & \mC{Freshwater algae suspended in sodium alginate beads} \\
Randomization      & \mC{The algae beads will be randomly assigned to a specific color filter} \\
Independent variable (IV) & \mC{The color of the light filter placed on the algae beads} \\ \midrule
Treatment groups   & 2 & 3 \\ 
Independent trials & 2 & 3 \\ \midrule
Dependent variable (DV) & \mC{The rate of photosynthesis\slash the amount of oxygen found in the samples} \\
Constants          & \mC{Stuff about project} \\
\bottomrule
\end{tabularx}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .