21

When we paste a table from a note pad or word or any other source its not coming in a good table format in this Stack Overflow question editor/text box space. My question is how do you make an unscrambled table (good format table) here. What do you do to make this happen? For example I paste the following table from Notepad, but it looks non-understandable:

ID LinkID PC TotalnoofoccurenceofID

10R46 R*1005 8017 2
10R46 R*10335 5019 2
100R91 R*1005 8017 1
10R91 R*243 8870 1
10M95 R*4918 8305 3
10M95 R*9017 8305 3
10M95 R*9470 8221 3

I saw some people changed this into a good HTML-like table format.

2
  • you can use <pre></pre> tag, around your table Commented Jan 18, 2017 at 9:12
  • Note that in December 2020, SO added Table Support to its dialect of Markdown. Commented Dec 17, 2020 at 16:42

2 Answers 2

20
  1. Make sure the table's columns are separated by spaces — no tabs.
  2. Double check that there are no tabs.
  3. Make sure once more that there are no tabs.
  4. Make sure the table looks sane in a monowidth font (Courier or equivalent).
  5. Check that there are no tabs.
  6. Copy the table from the editor to the question or answer.
  7. Select the table.
  8. Press the {} button above the edit box to indent it as code.
  9. Use 2 spaces to separate columns; you can use 3 or 4 if the table will fit across the page, but not more.
  10. Avoid the horizontal scroll bar if at all possible.

Did I mention making sure there are no tabs in the data?

ID      LinkID   PC    TotalNoOfOccurencesOfID
10R46   R*1005   8017  2
10R46   R*10335  5019  2
100R91  R*1005   8017  1
10R91   R*243    8870  1
10M95   R*4918   8305  3
10M95   R*9017   8305  3
10M95   R*9470   8221  3

December 2020 — Stack Overflow Markdown now supports tables

Stack Overflow's dialect of Markdown now supports tables.

That means the table in the question can be rendered like this:

ID LinkID PC TotalNoOfOccurencesOfID
10R46 R*1005 8017 2
10R46 R*10335 5019 2
100R91 R*1005 8017 1
10R91 R*243 8870 1
10M95 R*4918 8305 3
10M95 R*9017 8305 3
10M95 R*9470 8221 3

The Markdown used for that table is:

| ID      | LinkID   | PC    | TotalNoOfOccurencesOfID |
|:--------|:---------|:------|:-----------------------:|
| 10R46   | R*1005   | 8017  | 2 |
| 10R46   | R*10335  | 5019  | 2 |
| 100R91  | R*1005   | 8017  | 1 |
| 10R91   | R*243    | 8870  | 1 |
| 10M95   | R*4918   | 8305  | 3 |
| 10M95   | R*9017   | 8305  | 3 |
| 10M95   | R*9470   | 8221  | 3 |

It's still worth making sure there aren't tabs in the table, though.

5
  • 8
    Should I check to make sure there are no tabs?
    – TARKUS
    Commented Apr 22, 2017 at 14:04
  • 1
    If you haven't checked a couple of times already, another check is probably a good idea. Commented Apr 22, 2017 at 14:06
  • 1
    I'm using this answer as my tutorial on the subject.
    – TARKUS
    Commented Apr 22, 2017 at 14:07
  • But this is considered as code and error in submitting question It looks like your post is mostly code; please add some more details.
    – Prashanth
    Commented May 14, 2020 at 10:28
  • Exactly what is it that makes SE interpret your example as a table? The header row? The horizontal row on the second row? The spaces before and/or after the pipes? The colons? I am trying to make a table without a header row but it just comes out as regular text.
    – d-b
    Commented Jun 5, 2023 at 22:16
9

To add to the fixed-width idea, if you have lots of data (mostly not a good idea, but it does happen...). you can use two code blocks to make sure the header is always visible.

    ID      LinkID   PC    TotalNoOfOccurencesOfID

<!-- -->

    10R46   R*1005   8017  2
    10R46   R*10335  5019  2
    100R91  R*1005   8017  1
    10R91   R*243    8870  1
    10M95   R*4918   8305  3
    10M95   R*9017   8305  3
    10M95   R*9470   8221  3

displays as

ID      LinkID   PC    TotalNoOfOccurencesOfID
10R46   R*1005   8017  2
10R46   R*10335  5019  2
100R91  R*1005   8017  1
10R91   R*243    8870  1
10M95   R*4918   8305  3
10M95   R*9017   8305  3
10M95   R*9470   8221  3

Again, you should rarely have enough data that this should matter, but sometimes you do (scroll down a bit; it's under the heading Additional Support).

2
  • Note that the mobile theme uses neither scrollbars (but line wrapping), nor a fixed width font (a recent change; maybe a bug). Wide or tall code blocks are simply unreadable there.
    – Arjan
    Commented Feb 9, 2014 at 8:00
  • Ah, the lack of a fixed width font is only a problem on some devices. The lack of scrollbars is by design though.
    – Arjan
    Commented Feb 9, 2014 at 8:08

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