Skip to content
TheChatArchiveThe Chat Archive
DeepSeekdeepseek-r1-0528· DeepSeekHugging Face LMArena Human Preference 140K

I'm making a table in latex with the booktabs package. I would like some of the…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-opus-4-20250514’s answer.
  1. User

    I'm making a table in latex with the booktabs package. I would like some of the horizontal lines from midrule to only go partway across the table. For example if the table has 12 columns I might like one of the midrules to only go across 6 of them.

  2. DeepSeek Assistant

    To create a partial horizontal line across specific columns in a LaTeX table using the booktabs package, use the \cmidrule command. This command allows you to specify a range of columns for the line and optionally trim the ends to adjust spacing.

    Key Solution:

    • Command: \cmidrule{start-end}
    • Trimming: Add (l) or (r) to trim the left/right end (e.g., \cmidrule(r){1-6} trims the right edge).

    Example:

    Create a table with 12 columns and a partial line spanning columns 1 to 6:

    \documentclass{article}
    \usepackage{booktabs}
    
    \begin{document}
    \begin{tabular}{*{12}{c}} % 12 centered columns
      \toprule
      A1 & A2 & A3 & A4 & A5 & A6 & A7 & A8 & A9 & A10 & A11 & A12 \\
      \cmidrule{1-6} % Line from column 1 to 6
      B1 & B2 & B3 & B4 & B5 & B6 & B7 & B8 & B9 & B10 & B11 & B12 \\
      \bottomrule
    \end{tabular}
    \end{document}
    

    Advanced Usage:

    • Multiple Lines: Stack \cmidrule commands for disjoint segments:
      \cmidrule(r){1-6} \cmidrule(l){8-12} % Line from 1-6 and 8-12 (gap at column 7)
      
    • Trimming: Use (lr), (l{0.5em}), or (r{0.5em}) for custom trimming.

    Important Notes:

    1. Column Counting: Columns are numbered starting from 1.
    2. Multi-Column Cells: Rules align with physical columns, not merged cells. Use column indices that match the underlying structure.
    3. Consistency: Place \cmidrule immediately after the row it follows (no empty lines).

    Full Example with Trimming:

    \documentclass{article}
    \usepackage{booktabs}
    
    \begin{document}
    \begin{tabular}{cccccccccccc}
      \toprule
      \multicolumn{6}{c}{Group 1} & \multicolumn{6}{c}{Group 2} \\
      \cmidrule(r){1-6} \cmidrule(l){7-12} % Trimmed rules with a gap
      Col1 & Col2 & Col3 & Col4 & Col5 & Col6 & Col7 & Col8 & Col9 & Col10 & Col11 & Col12 \\
      \midrule
      A & B & C & D & E & F & G & H & I & J & K & L \\
      \bottomrule
    \end{tabular}
    \end{document}
    

    This approach ensures clean, professional tables with partial lines tailored to your column ranges.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.