TransWikia.com

Align left side of table with parindent

TeX - LaTeX Asked by James Skinner on February 5, 2021

I am using the tabularx environment to present formal arguments, and at the moment the left column is aligned with the left margin of the text and the right column is aligned with the right margin. For instance:

enter image description here

How can I get the left column to be aligned with the paragraph indent, but the right column to stay aligned with the right margin? I’ve tried using the changepage package and the adjustwidth command but that doesn’t seem to be helping, nor does adding hspace{parindent} in various places. I’m sure there’s a really simple way to do it but I don’t know how.

Here’s a MWE:

documentclass[12pt]{article}

usepackage{tabularx} %tables
usepackage{tabulary} %tables
usepackage{lipsum}
usepackage{upgreek} %greek letters
usepackage{amssymb} %modal operators

begin{document}

lipsum[1-2]

begin{table}[h!]
    centering
    setlength{extrarowheight}{3pt}
    begin{tabularx}{textwidth}{@{}rXr@{}}
        (1) & $varnothing vdash pi leftrightarrow val(ulcorner pi urcorner, ulcorner bot urcorner)$ & ($pi$ def.)
        (2) & $pi vdash pi$ & (Assumption)
        (3) & $pi vdash val(ulcorner pi urcorner, ulcorner bot urcorner)$ & (1,2, MP)
        (4) & $pi vdash bot$ & (2,3, textit{V-Detach})
        (5) & $varnothing vdash val(ulcorner pi urcorner, ulcorner bot urcorner)$ & (4, textit{V-Schema})
        (6) & $varnothing vdash pi$ & (1,5, MP)
        (7) & $varnothing vdash bot$ & (5,6, textit{V-Detach})
    end{tabularx}
end{table}

lipsum[3-4]


end{document}

Thanks!

2 Answers

The default value of parindent in the article document class is 1.5em. To achieve your formatting objective, it therefore suffices to change

begin{tabularx}{textwidth}{@{} rXr @{}}

to

begin{tabularx}{textwidth}{@{hspace{1.5em}} rXr @{}}

Since the overall usable width of the tabularx environment is decreased by 1.5em, LaTeX will automatically decrease the width of the X colum by that amount in order to assure that it will continue to fit inside the textblock.


Addendum: In case you don't happen to know the value of parindent, you could execute, say,

newlengthorigparindent
setlength{origparindent}{parindent}

sometime before starting the table environment and replace

begin{tabularx}{textwidth}{@{hspace{1.5em}} rXr @{}}

with

begin{tabularx}{textwidth}{@{hspace{origparindent}} rXr @{}}

Answered by Mico on February 5, 2021

You don't need to know the value of parindent, because TeX knows it.

Also you don't want a table environment, because it's a floating object and you quite likely want the material there, not somewhere else.

You can use an enumerate environment, properly set up with the help of enumitem. Pushing something to the right margin is easy with hfill, so long as the preceding material allows for the placement, more precisely it wouldn't overlap the label.

documentclass[12pt]{article}
usepackage{amsmath}
usepackage{lipsum}
usepackage{upgreek} %greek letters
usepackage{amssymb} %modal operators
usepackage{enumitem}

newenvironment{sidecond}
 {begin{enumerate}[
    label=(arabic*),
    leftmargin=dimexprparindent+labelsep,
    labelwidth=0pt,
    align=left
]}
{end{enumerate}}

begin{document}

lipsum[2][1-5]

begin{sidecond}
item $varnothing vdash pi leftrightarrow 
       mathit{val}(ulcorner pi urcorner, ulcorner bot urcorner)$hfill ($pi$ def.)

item $pi vdash pi$hfill (Assumption)

item $pi vdash mathit{val}(ulcorner pi urcorner, ulcorner bot urcorner)$hfill (1,2, MP)

item $pi vdash bot$hfill (2,3, textit{V-Detach})

item $varnothing vdash mathit{val}(ulcorner pi urcorner, ulcorner bot urcorner)$hfill
      (4, textit{V-Schema})

item $varnothing vdash pi$hfill (1,5, MP)

item $varnothing vdash bot$hfill (5,6, textit{V-Detach})
end{sidecond}

lipsum[4][1-3]


end{document}

enter image description here

A couple of final notes. I used mathit{val}, because otherwise the letters are too spaced out (because they denote the product of three variables). I left varnothing even if I abhor it for denoting the empty set.

Answered by egreg on February 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP