{"record":{"id":"9d2bcc4f396106bc","repo":"overleaf/overleaf","slug":"hline-must-be-at-the-start-of-a-row","errorCode":null,"errorMessage":"\\hline must be at the start of a row","messagePattern":"\\\\hline must be at the start of a row","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"services/web/frontend/js/features/source-editor/components/table-generator/utils.ts","lineNumber":392,"sourceCode":"      if (!lastCell?.multiColumn) {\n        if (lastCell) {\n          if (lastCell.content.trim() === '') {\n            lastCell.position.from = currentChild.to\n            lastCell.position.to = currentChild.to\n          } else {\n            lastCell.content += state.sliceDoc(\n              currentChild.from,\n              currentChild.to\n            )\n            lastCell.position.to = currentChild.to\n          }\n        }\n      }\n      // Try to preserve whitespace by skipping past it when locating cells\n    } else if (isHLine(currentChild)) {\n      const lastCell = getLastCell()\n      if (lastCell?.content.trim()) {\n        throw new Error('\\\\hline must be at the start of a row')\n      }\n      // push start of cell past the hline\n      if (lastCell) {\n        lastCell.position.from = currentChild.to\n        lastCell.position.to = currentChild.to\n      }\n      const lastRow = getLastRow()\n      lastRow.hlines.push({\n        position: { from: currentChild.from, to: currentChild.to },\n        // They will always be at the top, we patch the bottom border later.\n        atBottom: false,\n      })\n    } else {\n      // Add to the last cell\n      if (!getLastCell()) {\n        getLastRow().cells.push({\n          content: '',\n          position: { from: currentChild.from, to: currentChild.from },","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/overleaf/overleaf/blob/28ad3b03b71cb4311decdcb55c36b33ec10d72db/services/web/frontend/js/features/source-editor/components/table-generator/utils.ts#L374-L410","documentation":"The table-generator parses LaTeX tabular bodies into a row/cell structure and allows \\hline only at the start of a row (before any cell content). When an \\hline appears after a cell that already has non-empty content, parseTabularBody throws this error because it cannot represent a mid-row hline in its model. It is thrown to reject tabular structures (e.g. \\hline separating cells within one row) that the table generator does not support.","triggerScenarios":"Calling tableData/generateTable on a tabular body where an \\hline node appears after a cell with non-trimmed content in the same row, e.g. `a & b \\\\hline \\\\ c` or `a \\hline` instead of `a \\\\ \\hline`.","commonSituations":"Hand-written LaTeX pasted into the source editor where \\hline was used without a row-ending `\\\\` before it; mixing multirow/multicolumn hand-edits; editors converting tables that place rules mid-row.","solutions":["Add a row separator `\\\\` immediately before the misplaced \\hline so it starts a new row","Remove the redundant \\hline if it duplicates an existing rule at the row boundary","Rewrite the row so all \\hline commands appear only at the start of rows"],"exampleFix":"// before\n\\begin{tabular}{ll}\n  a & b \\hline \\\\\n  c & d\n\\end{tabular}\n// after\n\\begin{tabular}{ll}\n  \\hline\n  a & b \\\\\n  \\hline\n  c & d\n\\end{tabular}","handlingStrategy":"validation","validationCode":"function validateHlinePositions(latexBody) {\n  // every \\hline must be preceded (ignoring whitespace) by a row end\n  return !/[^\\\\](\\s|\\n)*\\\\hline/.test(latexBody.replace(/\\\\\\\\[\\s\\S]*?\\\\hline/g, '')) &&\n    !/(?<![\\\\\\\\][ \\t]*\\n)[ \\t]*\\S[^\\n]*\\\\hline/.test(latexBody);\n}\n// simpler practical check: each \\\\hline must follow a \\\\ line break or \\begin{tabular}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the visual table editor instead of hand-editing tabular LaTeX","Always end a row with \\\\ before adding \\hline","Lint pasted LaTeX for \\hline not at line start before saving"],"tags":["latex","table-generator","parser"],"backgroundTag":"latex-hline-misplaced","analyzedSha":"28ad3b03b71cb4311decdcb55c36b33ec10d72db","analyzedAt":"2026-09-03T02:10:22.807Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}