Problem with converting a text document to a table

When I convert a text document to a table (with 2 columns), there is a large space before the text in the right hand column. The text doesn’t align to the left of the column like it should. Can anyone tell me how to fix this problem so that the text aligns correctly to the left of the column?

(ajlittoz is tired to fix the non usage of the “slide” tool instead of the “upload” tool)

Share a sample file. Screenshots are useless.

What happened to the semi-colons? Were they used as separators for conversion to Table, if that is the case then what happened to the existing tab stops? Are they inside the table now?

With the text layout I see I would have thought that selecting your list, then clicking Table > Convert > Text to Table and under Separate Text At selecting Tabs would be the normal way, but maybe you wanted to remove the semi-colons at the end bit not within the text?

When you are editing or still writing your text, make sure that View - Formatting Marks (Ctrl+F10) is enabled. That way you can see spaces, paragraph marks, tab stops and much more. It’s an essential tool for solving problems like the one you have. Without it, it’s just about impossible to say what went wrong here, there are several possible causes.

Posting as an answer to this comment:

I am unable to reset the tabs to a single tab

Here is a macro from Andrew Pitonyak’s Useful Macro Information for OpenOffice.org to remove empty space, including squeezing multiple tabs to a single one:

Function IsAnythingSelected(oDoc As Object) As Boolean
  Dim oSels  'All of the selections
  Dim oSel         'A single selection
  Dim oCursor      'A temporary cursor
  
  IsAnythingSelected = False
  If IsNull(oDoc) Then Exit Function
  ' The current selection in the current controller. 
  'If there is no current controller, it returns NULL.
  oSels = oDoc.getCurrentSelection()
  If IsNull(oSels) Then Exit Function

  REM I have never seen a selection count of zero
  If oSels.getCount() = 0 Then Exit Function

  REM If there are multiple selections, then certainly 
  REM something is selected
  If oSels.getCount() > 1 Then 
    IsAnythingSelected = True
  Else
    REM If only one thing is selected, however, then check to see 
    REM if the selection is collapsed. In other words, see if the 
    REM end location is the same as the starting location.
    REM Notice that I use the text object from the selection object
    REM because it is safer than assuming that it is the same as the
    REM documents text object.
    oSel = oSels.getByIndex(0)
    oCursor = oSel.getText().CreateTextCursorByRange(oSel)
    If Not oCursor.IsCollapsed() Then IsAnythingSelected = True
  End If
End Function

Function GetLeftMostCursor(oSel As Object) As Object
  Dim oRange   'Left most range.
  Dim oCursor  'Cursor at the left most range.
  
  If oSel.getText().compareRegionStarts(oSel.getEnd(), oSel) >= 0 Then
    oRange = oSel.getEnd()
  Else
    oRange = oSel.getStart()
  End If
  oCursor = oSel.getText().CreateTextCursorByRange(oRange)
  oCursor.goRight(0, False)
  GetLeftMostCursor = oCursor
End Function

Function GetRightMostCursor(oSel As Object) As Object
  Dim oRange   'Right most range.
  Dim oCursor  'Cursor at the right most range.
  
  If oSel.getText().compareRegionStarts(oSel.getEnd(), oSel) >= 0 Then
    oRange = oSel.getStart()
  Else
    oRange = oSel.getEnd()
  End If
  oCursor = oSel.getText().CreateTextCursorByRange(oRange)
  oCursor.goLeft(0, False)
  GetRightMostCursor = oCursor
End Function

Function CreateSelectedTextIterator(oDoc As Object, sPrompt As String, oCurs()) As Boolean
  Dim lSelCount As Long       'Number of selected sections.
  Dim lWhichSelection As Long 'Current selection item.

  Dim oSels  'All of the selections
  Dim oSel         'A single selection.
  Dim oLCurs     'Cursor to the left of the current selection.
  Dim oRCurs     'Cursor to the right of the current selection.

  CreateSelectedTextIterator = True
  If Not IsAnythingSelected(ThisComponent) Then
    Dim i%
    i% = MsgBox("No text selected!" + Chr(13) + sPrompt, _
      1 OR 32 OR 256, "Warning")
    If i% = 1 Then
      oLCurs = oDoc.getText().createTextCursor()
      oLCurs.gotoStart(False)
      oRCurs = oDoc.getText().createTextCursor()
      oRCurs.gotoEnd(False)
      oCurs = DimArray(0, 1)
      oCurs(0, 0) = oLCurs
      oCurs(0, 1) = oRCurs
    Else
      oCurs = DimArray()
      CreateSelectedTextIterator = False
    End If
  Else
    oSels = ThisComponent.getCurrentSelection()
    lSelCount = oSels.getCount()
    oCurs = DimArray(lSelCount - 1, 1)
    For lWhichSelection = 0 To lSelCount - 1
      oSel = oSels.getByIndex(lWhichSelection)
      REM If I want to know if NO text is selected, I could
      REM do the following:
      REM oLCurs = oSel.getText().CreateTextCursorByRange(oSel)
      REM If oLCurs.isCollapsed() Then ...
      oLCurs = GetLeftMostCursor(oSel)
      oRCurs = GetRightMostCursor(oSel)
      oCurs(lWhichSelection, 0) = oLCurs
      oCurs(lWhichSelection, 1) = oRCurs
    Next
  End If
End Function

Function IsWhiteSpace(iChar As Integer) As Boolean
  Select Case iChar
  Case 9, 10, 13, 32, 160
    IsWhiteSpace = True
  Case Else
    IsWhiteSpace = False
  End Select  
End Function

Function RankChar(iPrevChar, iCurChar) As Integer
  If Not IsWhiteSpace(iCurChar) Then      'The current char is not white space, ignore it
    RankChar = 0
  ElseIf iPrevChar = 0 Then               'Start of a line and current char is white space
    RankChar = 1                          'so delete the current character.
  ElseIf Not IsWhiteSpace(iPrevChar) Then 'Current char is white space but previous is not
    RankChar = 0                          'so ignore the current charcter.
  ElseIf iPrevChar = 13 Then              'Previous char is highest ranked white space
    RankChar = 1                          'so delete the current character.
  ElseIf iCurChar = 13 Then               'Current character is highest ranked white space
    RankChar = -1                         'so delete the previous character.
  ElseIf iPrevChar = 10 Then              'No new Pars so see if previous char is new line
    RankChar = 1                          'so delete the current character.
  ElseIf iCurChar = 10 Then               'No new Pars so see if the current char is new line
    RankChar = -1                         'so delete the previous character.
  ElseIf iPrevChar = 9 Then               'No new Lines so see if the previous char is tab
    RankChar = 1                          'so delete the current character.
  ElseIf iCurChar = 9 Then                'No new Lines so see if the current char is a tab
    RankChar = -1                         'so delete the previous character.
  ElseIf iPrevChar = 160 Then             'No Tabs so check previous char for a hard space
    RankChar = 1                          'so delete the current character.
  ElseIf iCurChar = 160 Then              'No Tabs so check current char for a hard space
    RankChar = -1                         'so delete the previous character.
  ElseIf iPrevChar = 32 Then              'No hard spaces so check previous for a space
    RankChar = 1                          'so delete the current character.
  ElseIf iCurChar = 32 Then               'No hard spaces so check current for a space
    RankChar = -1                         'so delete the previous character.
  Else                                    'Should probably not get here
    RankChar = 0                          'so simply ignore it!
  End If
End Function

Sub RemoveEmptySpace
  Dim oCurs(), i%
  If Not CreateSelectedTextIterator(ThisComponent, _
    "ALL empty space will be removed from the ENTIRE document?", oCurs()) Then Exit Sub
  For i% = LBOUND(oCurs()) To UBOUND(oCurs())
     RemoveEmptySpaceWorker (oCurs(i%, 0), oCurs(i%, 1))
  Next i%
  MsgBox "Farite"
End Sub

Sub RemoveEmptySpaceWorker(oLCurs As Object, oRCurs As Object)
  Dim sParText As String, i As Integer
  Dim oText

  oText = oLCurs.getText()
  If IsNull(oLCurs) Or IsNull(oRCurs) Or IsNull(oText) Then Exit Sub
  If oText.compareRegionEnds(oLCurs, oRCurs) <= 0 Then Exit Sub

  Dim iLastChar As Integer, iThisChar As Integer, iRank As Integer
  iLastChar = 0
  iThisChar = 0
  oLCurs.goRight(0, False)
  Do While oLCurs.goRight(1, True)
    iThisChar = Asc(oLCurs.getString())
    i = oText.compareRegionEnds(oLCurs, oRCurs)
    'If at the last character!
    'Then always remove white space
    If i = 0 Then
      If IsWhiteSpace(iThisChar) Then oLCurs.setString("")
      Exit Do
    End If
    'If went past the end then get out
    If i < 0 Then Exit Do
    iRank = RankChar(iLastChar, iThisChar)
    If iRank = 1 Then
      'I am about to delete this character. 
      'I do not change iLastChar because it did not change!
      'Print "Deleting Current with " + iLastChar + " and " + iThisChar
      oLCurs.setString("")
    ElseIf iRank = -1 Then
      'This will deselect the selected character and then select one
      'more to the left.
      oLCurs.goLeft(2, True)
      'Print "Deleting to the left with " + iLastChar + " and " + iThisChar
      oLCurs.setString("")
      oLCurs.goRight(1, False)
      iLastChar = iThisChar
    Else
      oLCurs.goRight(0, False)
      iLastChar = iThisChar
    End If
  Loop
End Sub

Run RemoveEmptySpace() on a selection or for the entire text.

Well, I read through that, but I don’t understand it. I speak 4 languages, but not that one. :slight_smile:

C:\fakepath(new9f) Hmong Vocabulary List, Eng-Hmg, Appendix, semi-colons set differently.docx

C:\fakepath(new9f) Hmong Vocabulary List, Eng-Hmg, Appendix, table after semi-colons set differently.docx

Thanks to everyone for their replies and suggestions (especially Foris V). I checked the documents with the Formatting Marks added, which showed the tabs. I redid the original document, using tabbing to set the semicolon right before where I wanted the right column to start, (instead of setting the semicolons after the end of the words in the left column and tabbing to where I wanted the right column to begin). Then, when I converted it to a table, it came out correct, with the words in the right column all the way to the left of that column. This does work, but I don’t like having the semicolon right before the first word in the right column. (I’m converting this to a table so that I can reverse the 2 columns by cutting and pasting, resulting in 2 vocabulary lists, one English to Hmong, and the other Hmong to English, so I will be using the original document.) When I did this in Microsoft Word on another document a few years ago, I think I just set the semicolon at the end of the words in the left column. I’ll attach screenshots and sample files.

In response to Earnest Al - Yes, I was using semi-colons as seperator markers to indicate where to divide each line into 2 columns. I tried setting the separator as tabs, but it created a document with many columns, whereas I only wanted 2 columns.

(edited by ajlittoz - once again: the upload tool is not the same as the slide tool, though they are based on the same device)

This is not a solution to your question but rather a comment (thanks are really appreciated) but it would have been better in a comment.

Your multiple use of tabs is faulty. A single tab is just enough. To align you need only to define it in the paragraph style.

You are using Default Paragraph Style* everywhere. This is faulty because this style defines defaults for all others. The “normal” style for text is Text Body.

Working with Writer implies you should save as .odt. Saving as .odx “.docx” will cause repeatedly compatibility issues at load and save times. Always save in native format otherwise this ruins carefully crafted formatting.

Learn to work with styles.

will cause repeatedly compatibility issues at load and save times

Moreover, it poses a very high risk of losing your work completely.

Thanks for the new suggestions. There are 12 tabs that are set automatically when I open a page. I’m unable to change that. I spent about 30 minutes today trying to understand the “Inserting and Editing Tab Stops” page at help.libreoffice.org, but was unable to set the page to just 1 tab. The instructions for deleting a tab say “To delete a tab, hold down the mouse button while you drag the tab outside the ruler.” That didn’t work. I tried dragging the tab stops in the ruler in different directions - up, sideways, down - but the tab wouldn’t delete. I also tried setting the tabs via right click > paragraph > edit style > tabs, but was unable to reset the tabs.
Regarding the suggestion to work with the document in the odf format and to use the Text Body paragraph style - I tried both of these suggestions, but the problem remains (converting text to table with the words in the right column aligned to the left, without needing to have a semicolon immediately before the first word).

Edit: I am now able to set a page to have a single tab on a new document by dragging the tab stop in the ruler to the right. However, I am unable to reset the tabs to a single tab on the document that I’ve already typed.

In the ruler, you see two kinds of tabs. The bold ones are those you set explicitly. The thin ones (normally at right after the last explicit one) are implicit evenly spaced according to Tools>Options, LibreOffice Writer>General, Tab stops option. The implicit ones cannot be removed.

The best way to handle the tab stops is through paragraph styles. This guarantees consistency across paragraphs which should be formatted identically.

All the buttons, rulers, keyboard shortcuts, … are provided for quick’n’dirty job or for mechanical typewriter nostalgia. LO Writer is based on styles. Read the Writer Guide to discover the various styles and practice to get accustomed to their power and versatility.

By playing around with the tab stops in the ruler, I was able to set just one stop on the document (at least on the left side where I wanted it). By dragging the tab stops to the right, I was able to set an explicit stop in the middle of the page, and the implicit stops to the left of that were dragged away. However, I now find that setting just one tab stop (as was suggested by Ajlittoz) does not solve my problem. When I convert the text to a table, I still have gaps in front of the words in the right column that come from the single tab that was set. I would post screenshots and sample files, but it seems that I am unable to do that in a comment.
By the way, to Ajlittoz - I don’t understand your note that “the upload tool is not the same as the slide tool, though they are based on the same device”.

The upload tool is accessed through the paperclip icon. Images are inserted in the question with the slide icon. Both end up in storing a file in the site database (this is what I mean with “same device”).

To post screenshots and sample files, edit your question. Scroll to the end. Type Enter twice at least to separate them. Add a descriptive note. Use the tools to upload the images/files.

@EricLibreOffice1253, Before converting the text to table, find all multiple tabs instances (\t+) and replace with a single tab (\t); needs to check Regular expressions. You will see the data a bit messy, meanwhile.

Starting off from your first screenshot, you can find all multiple tabs instances (\t+), and replace with none.

Tested with LibreOffice 6.4.7.2 (x64); OS: Windows 10.0.


Add Answer is reserved for solutions. If you think the answer is not satisfactory, add a comment below, or click edit (below your question) to add more information. Thanks.

Check the mark (Answer markCorrect answer mark) to the left of the answer that solves your question.

If the answer helped you, you can mark the up arrow (Upvote mark) that is on the left (to vote, you need to have karma of at least 5).